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.
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 TableWhere 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 |
|
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? |
 |
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2006-09-27 : 12:26:51
|
Where '%,'+@filed+',%' like '%,'+cast(filed as varchar(10))+',%'MadhivananFailing to plan is Planning to fail |
 |
|
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 2CDKristenKristen |
 |
|
|
|
|
|
|