Friday, 23 October 2015

Split first-name middle-name and last-name from full name using sql query


// using SUBSTRING

declare @name varchar(50)='krishna-chaturvedi'
SELECT top 2 SUBSTRING(@name, CHARINDEX('-', @name)+1, 8000)+'/' +SUBSTRING(@name, CHARINDEX('-', @name) + 1, 8000)

FROM mstuser


// using PARSENAME


declare @name varchar(100)= 'krishna-kumar-chaturvedi'
Select PARSENAME (Replace(@name,'-','.'),1)[LastName],
            PARSENAME (Replace(@name,'-','.'),2) [MiddleName],

            PARSENAME (Replace(@name,'-','.'),3)[FristName]

No comments:

Post a Comment

How to highlight selected text in notepad++

  –> To highlight a block of code in Notepad++, please do the following steps step-1  :- Select the required text. step-2  :- Right click...