日期:2014-05-17 浏览次数:20485 次
declare @s nvarchar(4000)
Select @s=isnull(@s+',','')+quotename([DutyDate])
from DutyInfo group by[DutyDate]
exec('select * from DutyInfo pivot (max([DutyName]) for [DutyDate] in('+@s+'))b ')
string str = "declare @s nvarchar(4000) Select @s=isnull(@s+',','')+quotename([DutyDate]) from DutyInfo where DutyDate between'" + DateTime.Now.ToString("yyyyMMdd") + "'and'" + dt.ToString("yyyyMMdd") + "'group by [DutyDate] exec('select * from (SELECT [DutyDate],[Dutyweek],[DutyName] FROM DutyInfo)a pivot (max([DutyName]) for [DutyDate] in('+@s+'))b order by case when Dutyweek=''星期一'' then 1 when Dutyweek=''星期二'' then 2 when Dutyweek=''星期三'' then 3 when Dutyweek=''星期四'' then 4 when Dutyweek=''星期五'' then 5 when Dutyweek=''星期六'' then 6 when Dutyweek=''星期日'' then 7 END ')";