日期:2014-05-16 浏览次数:20564 次
declare @T1 table([ItemID] NUMERIC(18,0),[ItemName] varchar(5))
insert @T1
select 1,'hello' union all
select 2,'word'
declare @T2 table([tid] int,[IDString] varchar(3))
insert @T2
select 1,'1,2'
--SELECT T1.* FROM @T1 T1 WHERE [ItemID] IN (Select IDString from @T2 WHERE TID=1)
--Error converting data type varchar to numeric.
SELECT * FROM @T1
WHERE CHARINDEX(','+LTRIM([ItemID])+',',','+(SELECT IDString from @T2 WHERE TID=1)+',')>0
/*
ItemID ItemName
--------------------------------------- --------
1 hello
2 word
*/