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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 insert comma seperated values in table with 2 colu
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

32 Posts

Posted - 02/12/2013 :  19:09:46  Show Profile  Reply with Quote
@id = 1,2,3,4,5
@name = 'NY, NJ, VA, DC,CA'

I have a temp table called #tmp (id int, name varchar(4))
I want to insert these above comma delimited values in this temp table.
So 1 has corresponding value = NY, 2 has NJ etc...so total 5 rows will be inserted.
Can u tell me the best way to code that?

In (Som, Ni, Yak)

17684 Posts

Posted - 02/13/2013 :  02:23:53  Show Profile  Reply with Quote
using fnParseList from http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033

INSERT INTO #tmp (id, name)
select     i.Data, n.Data
from       dbo.fnParseList(@id) i
inner join dbo.fnParseList(@name) n on i.RowID = n.RowID

Time is always against us

Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 02/13/2013 :  04:34:02  Show Profile  Reply with Quote
also see


SQL Server MVP

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.05 seconds. Powered By: Snitz Forums 2000