需求很簡單.
就是先select 出來的Table , 把Table 某一欄位值當字串組起來.
create table #tmp_listppl (empno varchar(7), ppl nvarchar(500))
insert into #tmp_listppl (empno, ppl) select '1', cname from dbo.v_epaperauth
--這時Table 會長的這個樣子
-- 1,王大明
-- 1,張小芉
-- 1, 李大
declare @list as nvarchar(500),@no as char(7)
set @list =''
set @no=''
update #tmp_listppl
set @list = ppl = (CASE WHEN @no <> empno THEN rtrim (ltrim(ppl)) ELSE @list + ';' + rtrim (ltrim(ppl)) END),
@no = empno
select empno,max(ppl)as auditno into #tmp from #tmp_listppl group by empno
select * from #tmp
--這時會這樣子 1, 王大明;張小芉;李大
drop table #tmp
drop table #tmp_listppl