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 |
|
John_Mc_2009
Starting Member
7 Posts |
Posted - 2009-02-17 : 13:43:00
|
Hi,We got list of comma separated values(eg: 2,5,7,102,24) and I need to get all the records which are matching with those numbers..For Eg, select * from table1 where table1.col1 in ('2,5,7,102,24')Issue is COL1 is of type INT (IDENTITY) and the above query is giving error.I tried with CONVERT(VARCHAR,table1.col1) ...but does not retreive any records....Can somebody please help me to get those records in table1?Thanks,Eric  |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-02-17 : 13:48:04
|
| use dynamic sql |
 |
|
|
sakets_2000
Master Smack Fu Yak Hacker
1472 Posts |
Posted - 2009-02-17 : 13:50:40
|
| [code]declare @var varchar(1000)set @var='2,5,7,102,24'exec ('select * from table1 where table1.[col1] in ('+@var+')')[/code] |
 |
|
|
sodeep
Master Smack Fu Yak Hacker
7174 Posts |
Posted - 2009-02-17 : 14:00:59
|
Why Dynamic SQL? Just use this:Select * from table1 where col1 in (2,5,7,102,24) |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-02-18 : 02:15:44
|
| declare @var varchar(1000)set @var='2,5,7,102,24'select * from table where '%,' + @var + ',%' LIKE '%,' + CAST( col1 AS VARCHAR(255)) +',%' |
 |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-02-18 : 04:02:16
|
| Also search for Array+SQL server in googleMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|
|
|