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
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Insert comma delimited values in to a table

Author  Topic 

zany
Starting Member

4 Posts

Posted - 2007-07-19 : 13:45:04
I have a comma delimited string with a length of more than 10,000 characters. I want to insert these comma delimited values into a table. How can I achieve this?

Here is what I have tried. It works fine if the input string is less than 8000 characters.

-- OrderIDs is the user input
-- sample input string '2345678, 3456789, 4567890, 5678901,...'
DECLARE @OrderIDs varchar(8000)

CREATE TABLE #t (OrdID int not null)

DECLARE @SQL VARCHAR(8000)

SELECT @SQL = 'insert into #t select '+
REPLACE (@OrderIDs, ',' , ' union select ')

-- Load values from comma delimited string into a table
EXEC ( @SQL )

any help is highly appreciated.

Thanks

dinakar
Master Smack Fu Yak Hacker

2507 Posts

Posted - 2007-07-19 : 13:48:35
This question has been answered several times in this forums. Do a search and you wil find dozens of links.

Dinakar Nethi
************************
Life is short. Enjoy it.
************************
http://weblogs.sqlteam.com/dinakar/
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2007-07-19 : 13:49:10
look around here for splitter functions.

_______________________________________________
Causing trouble since 1980
blog: http://weblogs.sqlteam.com/mladenp
Go to Top of Page

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2007-07-19 : 19:13:06
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=25830&SearchTerms=CSVTable
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=50648
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=76033


KH
[spoiler]Time is always against us[/spoiler]

Go to Top of Page
   

- Advertisement -