select first 3 characters in sql query
  • how can select first three character from column data in sql query like i have account code field who 001025 so i want to just three letter from start like 001 which query should i use.
  • 3 Comments sorted by
  • Vote Up0Vote Down farazali58farazali58
    205.00 Karma Accepted Answer
    SELECT CAST(LEFT(account code, 3) AS INT)
    From tablename

    but its work best on string like this

    Select left(cast(001025 as varchar), 3) from tablename
    for further details and related topics
  • Vote Up0Vote Down Syed_Muneeb_AhmedSyed_Muneeb_Ahmed
    5.00 Karma Accepted Answer
    SELECT LEFT(ColumnName, 3) AS varchar from TableName

    SELECT LEFT('001025' , 3) AS varchar

    SELECT SUBSTRING('001025', 1, 3)
  • thanks its working.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook


Popular Posts of the Week