| Author |
Topic  |
|
|
Kimi86
Yak Posting Veteran
54 Posts |
Posted - 06/14/2012 : 04:37:49
|
I have a column that contains 2 fields which are comma delimited. How to get the field AFTER the comma.?? Example: house,303 -> 303 Both the fields can have any number of characters but wont be more than 500 i guess.. |
|
|
senthil_nagore
Flowing Fount of Yak Knowledge
India
1006 Posts |
Posted - 06/14/2012 : 04:43:30
|
Try this
select SUBSTRING('house,303',CHARINDEX(',','house,303')+1,LEN('house,303'))
Senthil Kumar C ------------------------------------------------------ MCITP - Database Administration SQL SERVER 2008 MCTS - Database Development SQL SERVER 2008 |
 |
|
|
webfred
Flowing Fount of Yak Knowledge
Germany
8529 Posts |
Posted - 06/14/2012 : 05:01:40
|
declare @testColumn varchar(255) set @testColumn = 'house,303' select parsename(replace(@testColumn,',','.'),1)
No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
khtan
In (Som, Ni, Yak)
Singapore
16769 Posts |
Posted - 06/14/2012 : 05:13:40
|
declare @testColumn varchar(255)
set @testColumn = 'house,303'
select right(@testColumn, charindex(',', reverse(@testColumn)) - 1)
KH Time is always against us
|
 |
|
|
khtan
In (Som, Ni, Yak)
Singapore
16769 Posts |
Posted - 06/14/2012 : 05:16:03
|
or using SwePeso's fnParseString
select dbo.fnParseString(-2, ',', @testColumn),
dbo.fnParseString(1, ',', @testColumn)
KH Time is always against us
|
 |
|
|
webfred
Flowing Fount of Yak Knowledge
Germany
8529 Posts |
Posted - 06/14/2012 : 05:20:48
|
or what sunita would like to do:
stuff(@testColumn,1,charindex(',',@testColumn),'')
No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
|
webfred
Flowing Fount of Yak Knowledge
Germany
8529 Posts |
Posted - 06/14/2012 : 05:40:47
|
and you should redesign your database as soon as possible to avoid this mess 
No, you're never too old to Yak'n'Roll if you're too young to die. |
 |
|
| |
Topic  |
|