I'm trying to do a pivot, however the query I'm using combines several tables to provide the results I need. Here is my query:
Select lc.statename as 'Queue',
CONVERT(varchar(10), wfl.entrytime, 110) as 'EntryDate',
count(lc.statenum) as 'Count' -- CONVERT(varchar(10), wfl.entrytime, 110) as 'EntryDate'
FROM lcstate lc
INNER JOIN wflog wfl ON lc.statenum = wfl.statenum
INNER JOIN lifecycle lif ON wfl.lcnum = lif.lcnum
INNER JOIN itemdata id ON wfl.itemnum = id.itemnum
WHERE (lif.lcnum = '163')
AND (lc.statenum IN ('836', '837', '848', '863', '845', '859', '860', '864', '865', '866', '816', '867', '869', '868', '870', '872'))
AND wfl.exittime = '1964-01-01 00:00:00.000'
GROUP BY lc.statename, CONVERT(varchar(10), wfl.entrytime, 110)
Order by 1,2,3 desc
My results are as follows:
Queue Entry Date Count
----------------------------------------------------------------
Queue1 01/01/2017 15
Queue1 01/04/2017 9
Queue1 01/21/2017 27
Queue2 01/01/2017 4
Queue2 01/21/2017 12
Queue3 01/01/2017 54
And I'd like to use Column 1 as the column header and the Entry date as the Row header. So it looks something like this:
EntryDate Queue1 Queue2 Queue3
-----------------------------------------------
01/01/2017 15 4 54
01/04/2017 9 null null
01/21/2017 27 12 null
There are a lot of queues and entry dates involved and I'd like to make the headers dynamic if possible as the queue names change depending on who is running the report. I understand there is a lot of Pivot examples, but most that I've found doesn't quite do what I need. I don't need to do this conversion, however I'm trying to make it as user friendly as possible for the users.
Thanks in advance.