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.

 All Forums
 General SQL Server Forums
 Script Library
 Need cols in the query

Author  Topic 

sreeram
Starting Member

1 Post

Posted - 2013-08-13 : 05:32:32
Hi,
I have written the below query

select type_payment,booked_by,sum(grand_total) GrandTotal from jp_lr group by type_payment,booked_by order by type_payment;

The output looks like the below.

Type_Payment Booked_by Grand_total
====================================
ON A/C JPANRH 2204054.00
ON A/C JPBLRY 85261.00
ON A/C JPSC 216617.00
ON A/C JPTPTH 318560.00
PAID JPTPTH 184937.00
PAID JPBLRY 111139.00
PAID JPANRH 179866.00
PAID JPSC 71332.00
TOPAY JPANRH 1248390.00
TOPAY JPTPTH 596670.00
TOPAY JPBLRY 333283.00
TOPAY JPSC 1388396.00


But what i want is the below

Booked_by ON A/C PAID TOPAY GrandTotal
========================================================
JPANRH - - - ---- -----
JPBLRY
JPSC
JPTPTH


Please help me out, how to generate this query.

Thanks
Madhukar

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2013-08-13 : 05:43:58
See PIVOT queries.



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page
   

- Advertisement -