Please start any new threads on our new site at http://forums.sqlteam.com. 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
 
Register Now and get your question answered!
Username:
Password:
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  

cottage125
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?

khtan
In (Som, Ni, Yak)

Singapore
17689 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




KH
Time is always against us

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
52326 Posts

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

http://visakhm.blogspot.in/2013/01/delimited-string-split-xml-parsing.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

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