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.
| 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 followingselect left([Empl],patindex(('%,%'),[Empl])-1)as Firstname from table1 select right([Empl],patindex(('%,%'),[Empl])) as lastname from table1ONly 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 thisSELECT PARSENAME(REPLACE(Emp,',','.'),2) AS FirstName,PARSENAME(REPLACE(Emp,',','.'),1) AS LastNameFROM table1 |
 |
|
|
tommy35
Starting Member
2 Posts |
Posted - 2008-10-16 : 03:31:30
|
| thank you! |
 |
|
|
|
|
|
|
|