Wednesday, November 25, 2009

How to use SUBSTRING function with string

SUBSTRING can be used to return a part of character string.
The syntex for SUBSTRING will look like this:

SUBSTRING ( value ,start , length )

where Value is the column name or the expression.
Start is an interger or bigint that specifies where the returned characters start.
Length is an integer or bigint that specifies how many character of the Value will be returned.

For example if we want to reurn the first 2 characters from the [f_name] column from table [students] then the query should be like that:

use [northwind]
Go
select substring(f_name,2,2) from students
Go

No comments:

Post a Comment