0

Dear All!

I want to get my columns value into rows . i am taking sum of qty of each month . like this

select sum(Case when month(invoicedate) = 1 then qty else 0 end) as janQty,
sum(Case when month(invoicedate) = 1 then qty else 0 end) as febQty,
sum(Case when month(invoicedate) = 1 then qty else 0 end) as marQty,
.
.
.
from Invoices 

above query is returning result like this
janQty---------febQty---------marQty-------------
--156-----------678-------------345------

and my required format is

janqQty------156
febqQty------678
marqQty------345
.
.
.

i can use union all like this this

select 'jan' as month, sum(case when month(invoicedate) = 1 then qty else 0 end ) as Qty
from invoice

union all

select 'feb' as month, sum(case when month(invoicedate) = 1 then qty else 0 end ) as Qty
from invoice

union all

select 'mar' as month, sum(case when month(invoicedate) = 1 then qty else 0 end ) as Qty
from invoice
.
.
.
.

But i dont want to use this method, Please guide me how i can do this in a simple way.

Regards

3
Contributors
2
Replies
4
Views
4 Years
Discussion Span
Last Post by adam_k
This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.