How do I change the first name and last name from a given name, for example: I have a name "Krishna Kiran" with Krishna as the first name and Kiran as the last name (surname) in a column.
Now I need the output as "Kiran, Krishna", that is, lastname, firstname
. How c开发者_JS百科an I do this?
SELECT ISNULL(LastName + ', ', '')
+ ISNULL(FirstName, '') AS FormattedName FROM ...
declare @T table (Name varchar(50))
insert into @T values ('krishna kiran')
select
right(Name, len(Name)-charindex(' ', Name, 0))+', '+left(Name, charindex(' ', Name, 0))
from @T
Try This
Try This
UPDATE TableName set first_name=(@temp:=first_name),first_name=last_name,last_name=@temp;
refer the image : https://i.stack.imgur.com/ri2AU.jpg
精彩评论