I've got a similar question to a previous question of mine - Pivot Tables PHP/MySQL
In that query I knew that the row headers would be called and just needed to dynamically create the column headers. Now, however, I don't know the row headers either.
So I have a query
select eng, count, weekof from dbo.RPT_ENG_WEEK ('2013-03-03', '2013-03-16', '2013-03-03', '2013-03-16') order by eng, weekof asc
that is returning the following data:
eng count weekof
James 11 2013-03-03
James 12 2013-03-10
Bill 2 2013-03-03
Gary 15 2013-03-03
Gary 5 2013-03-10
Fred 3 2013-03-03
Fred 2 2013-03-10
So I'm then wanting to turn this into one row per eng and one column per weekof like below
week: 2013-03-03 2013-03-10
James: 11 12
Bill: 2 0
Gary: 15 5
Fred: 3 2
The answer I got in my previous question works a charm if I were to put in the names of the eng as static rows, but there are, potentially, 100 or so eng it could return and really don't want to have to manually keep updating the list!
I could probably work it out via a cursor in the SQL function, but is there a better way of doing it?