create table test12_1
(员工编号 int,
 扣款编号 varchar(20)
)create table test12_2
(扣款编号 int,
 扣款名称 varchar(50)
)insert into test12_1 select 100,'1,2'
union all select 101,'3'
union all select 102,'2,3,4'
union all select 103,'1,2,3'insert into test12_2 select 1,'迟到'
union all select 2,'早退'
union all select 3,'病假'
union all select 4,'事假'go--创建处理函数create function f_str(@扣款编号 varchar(50))
returns varchar(8000)
as
begin
declare @r varchar(8000)
set @r=''
select @r=@r+' '+扣款名称
from test12_2
where ','+@扣款编号+',' like '%,'+cast(扣款编号 as varchar)+',%'
return(stuff(@r,1,1,''))
end
go--调用实现查询select 员工编号,扣款名称=dbo.f_str(扣款编号)
from test12_1
go/* 查询结果员工编号       扣款名称 100          迟到 早退 
 101          病假
 102          早退 病假 事假
 103          迟到 早退 病假*/