上次问过的,不好意思啊,这是我的数据表,其中各字段意思为,日期,分店代码,员工姓名,班别
我要实现下面这样的效果
有点问题,就是 大家看到的那个 双飞燕 不是 801 这个机构的 其它都是,我的代码是这样写的 请问我该怎么修改,谢谢
declare @sql varchar(max),@i int,@name char(100),@Outal char(4) declare @tb table (id int identity(1,1),_name char(100)) select @Outal='801' insert into @tb select distinct cName from View_Scheduling where sOutal=@Outal select @i=1 while(@i<=(select count(*) from @tb)) begin select top 1 @name=_name from @tb where id not in (select top (@i-1) id from @tb) set @sql=isnull(@sql+','+@name+'=case cName when '''+@name+''' then temp end',@name+'=case cName when '''+@name+''' then temp end') set @i=@i+1 end set @sql='select sDate,'+@sql+' from (select sDate,cName,temp=stuff((select '',''+rtrim(eName) from View_Scheduling where sDate=t.sDate for xml path('''')),1,1,'''') from View_Scheduling t group by sDate,cName )t'exec(@sql)