I have the following working SQL pivot query:
SELECT ProjectID, TEDescription, [Sun],[Mon], [Tue], [Wed], [Thu], [Fri], [Sat]
SELECT EmployeeID, ProjectID, TEDescription, TEHours, LEFT(DATENAME(WEEKDAY, TEDate), 3) WeekDayName FROM TimeEntry
WHERE (EmployeeID='BJD' AND TEDate>='9/6/2015' And TEDate<='9/12/2015')
FOR WeekDayName IN ([Sun], [Mon], [Tue], [Wed], [Thu], [Fri], [Sat])
ORDER BY ProjectID
I would like to add the field TEID which matches the TEHours record in the pivot fields. I am thinking the additional output fields could be SunTEID, MonTEID and so on. Results would as follows:
ProjectID TEDescription Sun SunTEID Mon MonTEID ...
15-001 Testing 1.0 abc 2.0 def
15-001 More Testing 2.0 ghi 1.0 jkl
15-002 Coding 3.0 mno 1.0 pqr
15-003 Coding 2.0 stu 2.0 vwx
Any help here?