Author |
Topic |
natg504
Starting Member
14 Posts |
Posted - 2014-02-06 : 10:19:15
|
I have two tables…Table 1: DataSeriesSeriesID, SeriesName----------------------------1, SeriesOneName2, SeriesTwoName3, SeriesThreeName4, SeriesFourNameTable 2 : DataID, DatePosted, SeriesID, Value-----------------------------------1, 2013-01-31, 3, 382 2, 2013-01-31, 4, 5783, 2013-02-01, 1, 1234, 2013-02-01, 2, 4565, 2013-02-01, 3, 382 6, 2013-02-01, 4, 578...I’d like to figure out a way to do a query where I can have the data in a format more like this:DatePosted, SeriesOneName, SeriesTwoName, SeriesThreeName, SeriesFourName-----------------------------------------------------------------------------2013-01-31, NULL, NULL, 382, 5782013-02-01, 123, 456, 382, 578Is there any way to write a query or a couple of queries that would do that? Thanks! |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2014-02-06 : 16:43:54
|
[code]SELECT DatePosted, MAX(CASE WHEN SeriesID = 1 THEN Value ELSE NULL END) AS Series1Name, MAX(CASE WHEN SeriesID = 2 THEN Value ELSE NULL END) AS Series2Name, MAX(CASE WHEN SeriesID = 3 THEN Value ELSE NULL END) AS Series3Name, MAX(CASE WHEN SeriesID = 4 THEN Value ELSE NULL END) AS Series4NameGROUP BY DatePostedORDER BY DatePosted;[/code] Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA |
|
|
|
|
|