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 2000 Forums
 Transact-SQL (2000)
 Comma Seperated Values?

Author  Topic 

JDavis
Starting Member

8 Posts

Posted - 2006-09-26 : 15:18:11
Is there a way to insert into a table the comma seperated values that are contained in a query using the IN statement:

Select *
From Table
Where field IN ('123','63456','34577')


Keep in mind that these are strings seperated by commas and not all part of a single string itself like: ''123','1525','345767''
Also, I have no control over the values.
They are always passed to me as '23424','436456','456','457435'

Any help is appreciated!

Thanks,

JDavis

Kristen
Test

22859 Posts

Posted - 2006-09-26 : 15:28:13
Have a look at:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=55210&SearchTerms=CSV,Splitting%20delimited%20lists,Best%20split%20functions

Kristen
Go to Top of Page

JDavis
Starting Member

8 Posts

Posted - 2006-09-27 : 10:29:15
Hmm... I tried some of those examples, but it comes up and says too many arguments specified. I still dont see a way to pass comma seperated values where the values are in single quotes, but the commas are not in quotes. '1','2','3','etc...'
Any Ideas?
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-09-27 : 12:26:51
Where '%,'+@filed+',%' like '%,'+cast(filed as varchar(10))+',%'

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-09-27 : 13:38:04
"I still dont see a way to pass comma seperated values where the values are in single quotes, but the commas are not in quotes"

Well if you have a Text String in that format you could just remove all the single quotes, and then split on the commas - or remove the first and last character and then split on:

','

instead of just single quotes; or have your Splitter function "silently" remove surrounding quotes from the values - however, its a bit more tricky if the quotes are there to preserve any embedded commas - which is usually the case in a CSV file - e.g.:

"10, The High Street", Anytown, AnyShire, AB1 2CD

Kristen

Kristen
Go to Top of Page
   

- Advertisement -