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 |
|
soori457
Yak Posting Veteran
85 Posts |
Posted - 2009-06-08 : 06:26:26
|
| Hai Alldeclare @var varchar(32)set @var = '101,102,103,104,105,106'select * from emp where emp id in (cast(@var as int))This is my query, when am trying to execute this, am getting error that Failed to convert varchar value '101,102,103,104,105,106' to datatype intAnyone plz solve thisThanks in AdvanceSuresh Kumar |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
|
|
senthil_nagore
Master Smack Fu Yak Hacker
1007 Posts |
Posted - 2009-06-08 : 06:40:08
|
| You can do like this..You must use Dynamic SQL.set @query='select * from emp where emp_id in ('+@var+')'Exec (@query)Senthil.C------------------------------------------------------[Microsoft][ODBC SQL Server Driver]Operation canceled |
 |
|
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2009-06-08 : 06:47:35
|
I hope someone doesn't enter the value " 1); DROP TABLE Emp" E 12°55'05.63"N 56°04'39.26" |
 |
|
|
bklr
Master Smack Fu Yak Hacker
1693 Posts |
Posted - 2009-06-08 : 07:10:22
|
| select * from emp where '%,' + @var+ ',%' LIKE '%,' + CAST( empid AS VARCHAR(255)) +',%' |
 |
|
|
raky
Aged Yak Warrior
767 Posts |
Posted - 2009-06-08 : 08:47:27
|
| SELECT * FROM emp WHERE PATINDEX('%,'+ CAST(empid AS VARCHAR(30))+',%', ',' + @var + ',') > 0 |
 |
|
|
|
|
|
|
|