`

In的使用

    博客分类:
  • SQL
 
阅读更多

In的使用

declare @id int
declare @l int
declare @s varchar(50)
declare @r varchar(1000)
set @id=1
set @s=(select cids from A where id=@id)
set @l=1
set @r=''
while (@l<=len(@s))
begin 
if(@l<len(@s))
begin
set @r=@r+'select cid,[name] from B where cid in('+substring(@s,@l,1)+') union all '
end
else
begin
set @r=@r+'select cid,[name] from B where cid in('+substring(@s,@l,1)+')'
end
set @l=@l+2
end
exec(@r)

 

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics