请教
表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)
[解决办法]
declare @content varchar(200)
select top 1 @content=content from a
exec( 'select * from orders where content in( '+@content+ ') ')
[解决办法]
declare @content varchar(200)
select top 1 @content=content from a
exec( 'select * from orders where id in( '+@content+ ') ')
[解决办法]
create table A
(
id int,
content varchar(100)
)
insert A select 1, '11,22,33,44,55,66 '
insert A select 2, '77,88,99 '
create table B
(
T int
)
insert B select 11
insert B select 22
insert B select 88
select * from B where charindex(cast(T as varchar),(select top 1 content from A ))> 0
[解决办法]
--改用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)