My result is this:
Sitecode Month Amount -------- ----- ------ XX Jan 1000 XX Jan 3000 XX Apr 3000 XX Apr 1000
Result will show like this:
Sitecode MonthJAN MonthAPR -------- -------- -------- XX 4000 4000
closed as not a real question by Phil, ypercube, Martin Smith, Mark Storey-Smith, dezso Jan 16 '13 at 11:06
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.
As others have said this is known as a
If you know the values ahead of time, then you can hard-code the values. Prior to the
See SQL Fiddle with Demo.
The above two versions work great if you know the values ahead of time. If not, then you will use dynamic sql to create the result.
All 3 versions of this will return the same result:
As Martin Smith said, you need to pivot the data, whether with an explicit PIVOT as referenced or something like this (SQL Fiddle):