SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 Script Library
 Need cols in the query
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

sreeram
Starting Member

India
1 Posts

Posted - 08/13/2013 :  05:32:32  Show Profile  Reply with Quote
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

Sweden
30115 Posts

Posted - 08/13/2013 :  05:43:58  Show Profile  Visit SwePeso's Homepage  Reply with Quote
See PIVOT queries.



Microsoft SQL Server MVP, MCT, MCSE, MCSA, MCP, MCITP, MCTS, MCDBA
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.03 seconds. Powered By: Snitz Forums 2000