写个函数来做create function fn_Getnames(
@str varchar(100)
returns varchar(200)
as
begin
declare @r varchar(200)
declare @t varchar(100)
declare @x varchar(20)
set @r=''
set @t=@str
while charindex(';',@t)>0
begin
set @x=left(@t,charindex(';',@t)-1)
set @t=stuff(@t,1,charindex(';',@t),'')
select @r=@r+';'+name from b where id=@x
end
if @t<>''
select @r=@r+';'+name from b where id=@t
set @r=stuff(@r,1,1,'')
return @r
end
go--调用
select dbo.fn_Getnames(字段) as names from a
@str varchar(100)
returns varchar(200)
as
begin
declare @r varchar(200)
declare @t varchar(100)
declare @x varchar(20)
set @r=''
set @t=@str
while charindex(';',@t)>0
begin
set @x=left(@t,charindex(';',@t)-1)
set @t=stuff(@t,1,charindex(';',@t),'')
select @r=@r+';'+name from b where id=@x
end
if @t<>''
select @r=@r+';'+name from b where id=@t
set @r=stuff(@r,1,1,'')
return @r
end
go--调用
select dbo.fn_Getnames(字段) as names from a
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货