Another one for you SQL Server gurus...
I have a table like so...
AccountManager | Action | Count
-----------------------------------------------------
Joe | Client Negotiation | 10
Bloggs | Closing | 1
Aunty | Email | 12
Marie | Preparing Contract | 32
The Action column may have numerous different types of statuses which may not necessarily be fixed.
I need the output to be the following:
AccountManager | Client Negotiation | Closing | Email | Preparing Contract
--------------------------------------------------------------------------
Joe | 10 | 0 | 0 | 0
Bloggs | 0 | 1 | 0 | 0
Aunty | 0 | 0 | 12 | 0
Marie | 0 | 0 | 0 | 32
How could this be achieved? Help!
This is best handled by the reporting tool that you're using. Look for "Pivot table".
Follow the below walkthrough
http://www.tsqltutorials.com/pivot.php
Maybe something like this:
First the test data:
If you know that the columns are static. Then you can do this:
Otherwise you have to do a dynamic pivot like this:
First the unique column names:
Then the dynamic pivot like this:
Then in my case I will drop the temp table: