34,590
社区成员
发帖
与我相关
我的任务
分享
if object_id('tb') is not null drop table tb
go
create table tb(col varchar(3))
insert into tb select
'5' union select
'6' union select
'7'
declare @s varchar(10)
set @s='5,6'
exec('select * from tb where col in ('+@s+')')
col
----
5
6
(2 行受影响)
declare @s ='AI,PE,TE'
exec('select * from XXX.dbo.ECNDEPT
where dept in ('+@s+')')
declare @s varchar(50),@sql varchar(8000)
set @s='AI,PE,TE'
set @sql='Select * from XXX.dbo.ECNDEPT where dept in ('''+replace(@s,',',''',''')+''')'
exec (@sql)
Select *
from XXX.dbo.ECNDEPT
where dept in (convert(VARCHAR(50),XXX.dbo.ECNFUN2('AI,PE,TE,')))
Select *
from XXX.dbo.ECNDEPT
where dept in (convert(VACHAR(50),XXX.dbo.ECNFUN2('AI,PE,TE,')))