SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2008 Forums
 Transact-SQL (2008)
 How to get the field AFTER the comma
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Kimi86
Yak Posting Veteran

54 Posts

Posted - 06/14/2012 :  04:37:49  Show Profile  Reply with Quote
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  Show Profile  Visit senthil_nagore's Homepage  Send senthil_nagore a Yahoo! Message  Reply with Quote
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
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8529 Posts

Posted - 06/14/2012 :  05:01:40  Show Profile  Visit webfred's Homepage  Reply with Quote
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.
Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
16769 Posts

Posted - 06/14/2012 :  05:13:40  Show Profile  Reply with Quote

declare @testColumn varchar(255)
set 	@testColumn = 'house,303'
select	right(@testColumn, charindex(',', reverse(@testColumn)) - 1)



KH
Time is always against us

Go to Top of Page

khtan
In (Som, Ni, Yak)

Singapore
16769 Posts

Posted - 06/14/2012 :  05:16:03  Show Profile  Reply with Quote
or using SwePeso's fnParseString

select	dbo.fnParseString(-2, ',', @testColumn), 
	dbo.fnParseString(1, ',', @testColumn)



KH
Time is always against us

Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8529 Posts

Posted - 06/14/2012 :  05:20:48  Show Profile  Visit webfred's Homepage  Reply with Quote
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.
Go to Top of Page

webfred
Flowing Fount of Yak Knowledge

Germany
8529 Posts

Posted - 06/14/2012 :  05:40:47  Show Profile  Visit webfred's Homepage  Reply with Quote
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.
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000