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
 General SQL Server Forums
 New to SQL Server Programming
 parsing comma seperated text into fields

Author  Topic 

tommy35
Starting Member

2 Posts

Posted - 2008-10-15 : 13:14:04
HEllo,

My question is on parsing comma seperated text into fields.
I have the problem when on a table I have a field [employee]
and data is "John, Smith" on a row. I am trying to seperate the
firstname from the lastname using the following

select left([Empl],patindex(('%,%'),[Empl])-1)as Firstname from table1

select right([Empl],patindex(('%,%'),[Empl])) as lastname from table1

ONly the left statement works giving me John.
How could I resolve the lastname?

Thank you in advance

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-10-15 : 13:22:44
if the name field format is consistent always as firstname,lastname just use this

SELECT PARSENAME(REPLACE(Emp,',','.'),2) AS FirstName,
PARSENAME(REPLACE(Emp,',','.'),1) AS LastName
FROM table1
Go to Top of Page

tommy35
Starting Member

2 Posts

Posted - 2008-10-16 : 03:31:30
thank you!
Go to Top of Page
   

- Advertisement -