关于ms sql 函数的问题
我建立了一个名为f_hb
create function f_hb(@nuserid int)
returns varchar(50)
as
begin
declare @str varchar(50)
set @str = ' '
select @str = @str + ', ' + cast(ntrade as varchar) from tb_Person_Job where nuserid = @nuserid
set @str = right(@str , len(@str) - 1)
return(@str)
End
然后建立了一个视图
create view view_ttt as
select nuserid,dbo.f_hb(nuserid) as nTrade from tb_Person_Job
group by nuserid
------------------------------------------------------
现在view_ttt显示的结果是这样的
nuserid ntrade
---------- ----------------
58105 001,001,006
58104 001,001,001
58106 001,002
我想要的结果是这样的,没有重覆的
nuserid ntrade
---------- ----------------
58105 001,006
58104 001
58106 001,002
也就是说,如何在f_hb添加一个判断语句,去掉重覆的数据
[解决办法]
create function f_hb(@nuserid int)
returns varchar(50)
as
begin
declare @str varchar(50)
set @str = ' '
select @str = @str + ', ' + cast(ntrade as varchar) from (select distinct ntrade from tb_Person_Job where nuserid = @nuserid) t
set @str = right(@str , len(@str) - 1)
return(@str)
End
go