Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 SQL Query help

Author  Topic 

Sush
Starting Member

2 Posts

Posted - 2014-06-30 : 16:58:58
I have a column employee1 lastname,(comma) firstname and have another column employee2 which should be written as firstname lastname. How can i achieve this

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2014-06-30 : 17:19:50
lots of ways to do this, here is one way:
DECLARE @Employee1 VARCHAR(255) = 'lastname, firstname'

SELECT
RIGHT(@Employee1, LEN(@Employee1) - CHARINDEX(',', @Employee1) - 1)
,LEFT(@Employee1, CHARINDEX(',', @Employee1) - 1)
Go to Top of Page
   

- Advertisement -