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

Recommended Answers

All 2 Replies

A better question is perhaps why do you want to do this?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.