Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
keesvo
Starting Member
10 Posts |
Posted - 2015-03-24 : 11:35:25
|
Hello,I have a query which shows the results in the different rows. But I want the results of the month in columns instead of rows. Let make my question clear with the following example. Below my query and my results:query:select klaref, bkjref, monthref,case when monthref = '01' then SUM(amount) end as jan,case when monthref = '02' then sum(amount) end as feb,case when monthref = '03' then sum(amount) end as mrtfrom invoicesgroup by klaref, bkjref, perirefthe result is as following:klaref bkjref monthref jan feb mrt100001 2015 01 500100001 2015 02 300100001 2015 03 900But what I want is the following result:klaref bkjref jan feb mrt100001 2015 500 300 900Does someone know how I can realize this.thank you ! |
|
MichaelJSQL
Constraint Violating Yak Guru
252 Posts |
Posted - 2015-03-24 : 11:42:58
|
Use unpivothttps://technet.microsoft.com/en-us/library/ms177410(v=sql.105).aspx |
|
|
keesvo
Starting Member
10 Posts |
Posted - 2015-03-31 : 07:28:39
|
Thanx.That did the trick. |
|
|
|
|
|