Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
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
 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 total 5 rows will be inserted.
Can u tell me the best way to code that?

In (Som, Ni, Yak)

17689 Posts

Posted - 02/13/2013 :  02:23:53  Show Profile  Reply with Quote
using fnParseList from

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