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 |
|
matkwan
Starting Member
36 Posts |
Posted - 2002-10-18 : 06:35:34
|
| Hi I have problem retrieving records using IN operator. If I run this code, it says "Syntax error converting the varchar value '23, 26' to a column of data type int.":---------------------------------------------------DECLARE @DOMAIN_ID_LIST VARCHAR(20)SET @DOMAIN_ID_LIST = '23, 26'SELECT * FROM DOMAINWHERE DOMAIN_ID IN (@DOMAIN_ID_LIST)AND DELETED_FLAG = 0 ---------------------------------------------------But if I CAST the column then I don't get any record.---------------------------------------------------DECLARE @DOMAIN_ID_LIST VARCHAR(20)SET @DOMAIN_ID_LIST = '23, 26'SELECT * FROM DOMAINWHERE CAST(DOMAIN_ID AS VARCHAR(20)) IN (@DOMAIN_ID_LIST)AND DELETED_FLAG = 0 ---------------------------------------------------Please help.Matthew |
|
|
Page47
Master Smack Fu Yak Hacker
2878 Posts |
Posted - 2002-10-18 : 07:10:50
|
| I don't believe the IN operator will work like this.Consider a charindex expression .... charindex(convert(varchar,domain_id),@domain_id_list) > 0 ... or read though some of the articles here dealing with CSV.Jay White{0} |
 |
|
|
mnttr
Starting Member
9 Posts |
Posted - 2002-10-18 : 08:18:34
|
| DECLARE @DOMAIN_ID_LIST VARCHAR(20) SET @DOMAIN_ID_LIST = '23, 26' exec('SELECT * FROM DOMAIN WHERE DOMAIN_ID IN ('+@DOMAIN_ID_LIST+') AND DELETED_FLAG = 0 ')OK? |
 |
|
|
|
|
|