Instead of hard coding all the dates in pivot any samples/ideas for generating it dynamically for each month or the date rangeselect * from ( SELECT shift_type ,shift_date1, empid1 FROM #temp1 ) as sourceTable Pivot (MAX(shift_type) for shift_date1 in ([2015-10-01],[2015-10-02],[2015-10-03],[2015-10-04],[2015-10-05],[2015-10-06],[2015-10-07],[2015-10-08],[2015-10-09],[2015-10-10],[2015-10-11],[2015-10-12],[2015-10-13],[2015-10-14],[2015-10-15],[2015-10-16],[2015-10-17],[2015-10-18],[2015-10-19],[2015-10-20],[2015-10-21],[2015-10-22],[2015-10-23],[2015-10-24],[2015-10-25],[2015-10-26],[2015-10-27],[2015-10-28],[2015-10-29],[2015-10-30],[2015-10-31]) ) as PivotTable
↧