I would like to output the following table from my database
DateTime | Measure 1 | Measure 2
5-5-2011 | 35 | 45
4-5-2011 | 23 | 56
3-5-2011 | 22 | 56
My database in question contains data in this approximate layout
DateTime | Values | ID
5-5-2011 | 35 | Measure 1
5-5-2011 | 45 | Measure 2
4-5-2011 | 23 | Measure 1
4-5-2011 | 56 | Measure 2
3-5-2011 | 22 | Measure 1
3-5-2011 | 56 | Measure 2
Is there anyway I can get my desired output in a single SQL query. I can easily obtain my data through multiple select queries i.e.
SELECT DateTime, Values AS Measure 1 FROM database.table WHERE ID='Measure 1'
SELECT DateTime, Values AS Measure 2 FROM database.table WHERE ID='Measure 2'
However I need the data in a single query to build pretty pictures in MSSQL Report Builder.
The database in question contains millions of values for hundreds of measures. I am running MSSQL 2008.
I’ve looked into Union, Case etc but couldn’t get any method to work correctly.
Hopefully someone can help me. I’m stumped and don’t know the correct phrases to search for help on this problem. If I can crack this nut then i’ll pretty much have all the tools to do everything I want to do.
Thank you in advance
Could you not find some other name for the ID column that’s also a reserved word? 🙂