Reputation: 1373
I have a query like this.
After executing I'm getting following result.
What I want to do is for each Invoice No I want to show 'Amount' as a CashAmt and ChequeAmt in a one row. Currently there is 2 records for cash and cheque.
Upvotes: 0
Views: 77
Reputation: 62861
You're trying to pivot
your results. You can do this with group by
, max
and case
:
select mdr.invoiceno, mdr.invoicedate, mdr.customerid, mdr.netamount, cus.name,
max(case when pt.Name = 'Cash' then pay.amount end) CashAmt,
max(case when pt.Name = 'Cheque' then pay.amount end) ChequeAmt
from customer cus
....
group by mdr.invoiceno, mdr.invoicedate, mdr.customerid, mdr.netamount, cus.name
order by mdr.invoiceno
Upvotes: 3