----------代码
declare @content varchar(200)
select top 1 @content=content from a
select * from orders where content in(@content)
----------如何实现以下查询的结果
select * from others where id in(11,22,33,44,55,66)
...全文
1256打赏收藏
请教
表a id content 1 11,22,33,44,55,66 2 77,88,99 ----------代码 declare @content varchar(200) select top 1 @content=content from a select * from orders where content in(@content) ----------如何实现以下查询的结果 select * from others where id in(11,22,33,44,55,66)
--或者Like
Select T1.* from orders T1
Inner Join a T2
On ',' + T2.content + ',' Like '%,' + Cast(T1.id As Varchar) + ',%'
Where T2.id = (Select TOP 1 id From a)
--改用CharIndex,可以不用使用動態SQL語句
Select T1.* from orders T1
Inner Join a T2
On CharIndex(',' + Cast(T1.id As Varchar) + ',', ',' + T2.content + ',') > 0
Where T2.id = (Select TOP 1 id From a)