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 |
|
sharona
Yak Posting Veteran
75 Posts |
Posted - 2011-02-18 : 10:28:25
|
i have a field called name, it is the last name and first name seperated by a comma, i would like to parse the last name prior to the comma, how do i do that please? thank you  |
|
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2011-02-18 : 10:33:17
|
| SELECT LEFT(Name, CHARINDEX(',', Name)-1) FROM myTable |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2011-02-18 : 10:43:46
|
| [code]DECLARE @name varchar(100); SET @name = 'Kaiser,Brett'SELECT '"' +SUBSTRING(@name,1,CHARINDEX(',',@name)-1)+'"' AS LastName , '"'+SUBSTRING(@name,CHARINDEX(',',@name)+1,LEN(@name)-LEN(SUBSTRING(@name,1,CHARINDEX(',',@name)-1)))+'"' AS FirstName [/code]Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspxhttp://weblogs.sqlteam.com/brettk/http://brettkaiser.blogspot.com/ |
 |
|
|
sharona
Yak Posting Veteran
75 Posts |
Posted - 2011-02-18 : 10:53:28
|
| thank you i used to get first and last. LEFT(dbo.CV3CareProvider.DisplayName, CHARINDEX(',', dbo.CV3CareProvider.DisplayName)-1),SUBSTRING(dbo.CV3CareProvider.DisplayName,CHARINDEX(',',dbo.CV3CareProvider.DisplayName)+1,LEN(dbo.CV3CareProvider.DisplayName)-LEN(SUBSTRING(dbo.CV3CareProvider.DisplayName,1,CHARINDEX(',',dbo.CV3CareProvider.DisplayName)-1))), |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2011-02-18 : 12:02:17
|
| orLEFT(DisplayName, CHARINDEX(',', DisplayName)-1),RIGHT(DisplayName, CHARINDEX(',', reverse(DisplayName))-1)MadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|