Feeds:
Posts
Comments

Posts Tagged ‘CHARINDEX REVERSE SQL SERVER’

 

Assume a table having name column having First Name and Last
Name seprated by space.

 

First get the index of space from right and then use this index
value minus one to get as many charcters from end by using RIGHT operator.

 

Example:

 

CREATE
TABLE TableName

(

Name_Column
VARCHAR(100)

)

 

Go

 

INSERT
TableName

SELECT
‘A Singh’

UNION
ALL

SELECT
‘D Kumar’

Go

 

 

SELECT
RIGHT(Name_Column,
CHARINDEX(‘ ‘, REVERSE (Name_Column)) 1) AS [LastName]

FROM
TableName

Go

 

 

Result:

 

LastName

Singh

Kumar

Advertisements

Read Full Post »

%d bloggers like this: