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

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 insert comma seperated values in table with 2 colu

Author  Topic 

cottage125
Starting Member

32 Posts

Posted - 2013-02-12 : 19:09:46
@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)

17689 Posts

Posted - 2013-02-13 : 02:23:53
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
[spoiler]Time is always against us[/spoiler]

Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-02-13 : 04:34:02
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
   

- Advertisement -