SubString function in SQL Server

Posted by SheoNarayan under Sql Server category on | Views : 6782
The way we work with SubString function in C#, in the same way we have SubString function in SQL Server.

Lets say, you have flag field with numeric data type and you want to get first 3 and next 3 characters from its value, you can use following code snippets.

select cast(flag as varchar) as Flag, substring (cast(flag as varchar), 1, 3) as Mine,
substring (cast(flag as varchar), 4, 3) as Yours from testtable where autoid < 3

For field of varchar type, you do not need to use cast function.

Comments or Responses

Login to post response