我现在有一个SQL。类似以下:select app_id from a where id = 'A'结果:099889
099888
我现在像写一个方法,如果将上面的SQL用一个函数(假设叫为fun1)将其值变为
099889,099888
这样我就使用类型以下的场景:
select *
from tableA
where
fun1(select app_id from a where id = 'A') like '%099888%'
请高手么帮忙~~~谢谢!!
099888
我现在像写一个方法,如果将上面的SQL用一个函数(假设叫为fun1)将其值变为
099889,099888
这样我就使用类型以下的场景:
select *
from tableA
where
fun1(select app_id from a where id = 'A') like '%099888%'
请高手么帮忙~~~谢谢!!
returns nvarchar(30)
as
begin
declare @S nvarchar(30)
select
@S=isnull(@S+', ','')+ltrim(app_id)
from
A
where
id=@col
return @S
end
直接
select *
from tableA
where '099888' in (select app_id from a where id = 'A')
-- sql server 2005
select stuff((select ','+app_id from a where id = 'A' for xml path('') ),1,1,'')
因为是自动生成查询条件,目前的查询值只能放在后面,不能放到select前to #3
很好用~~谢谢