Saturday, August 22, 2009

SQL_Query_Substring

DECLARE @SampleString VARCHAR(MAX)
--I declare @SampleString cause i can easily increase the length of variable '@SampleString'
SELECT @SampleString = 'Sheeban Ahmed'

SELECT SUBSTRING(@SampleString,1,1) AS S
--S

SELECT SUBSTRING(@SampleString,1,2) AS SH
--Sh

SELECT SUBSTRING(@SampleString,1,0) AS BLANK
--<BLANK>

SELECT SUBSTRING(@SampleString,0,1) AS BLANK
--<BLANK>

SELECT SUBSTRING(@SampleString,-1,4) AS SH
--S

SELECT SUBSTRING(@SampleString,-1,0) AS BLANK
--<BLANK>

SELECT SUBSTRING(@SampleString,-10,12) AS S
--S

SELECT SUBSTRING(@SampleString,-10,25) AS [SHEEBAN AHMED]
--Sheeban Ahmed

No comments:

Post a Comment