Click here to Skip to main content
15,886,873 members
Articles / Database Development / SQL Server

Using Pivot In SQL for Reporting

Rate me:
Please Sign up or sign in to vote.
0.00/5 (No votes)
15 Mar 2011CPOL 6.8K   3  
select ExDate, SUM(case when Dept='A' then expense else 0 end)[Store A Expense],SUM(case when Dept='B' then expense else 0 end)[Store B Expense],SUM(case when Dept='C' then expense else 0 end)[Store C Expense]from expenseTable where Dept in ('A','B','C') group by ExDate

Alternatives

Members may post updates or alternatives to this current article in order to show different approaches or add new features.

Please Sign up or sign in to vote.
28 Feb 2011pankajupadhyay29 2 alternatives  
Nice and fast way for reporting
Please Sign up or sign in to vote.
11 Mar 2011Feleke Feyissa
select * from(SELECT l.Prepared_Date as Prepared_Date , m.Material_Code as Material_Code ,n.Name as Name,n.Description as Description , m.Quantity as Quantity,n.Unit_Of_Measure as Unit_Of_Measure , m.Status as Status...

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Team Leader
India India
Kannan KR, Team Lead working in a Mobile Application Development Company in Noida, India. Having 8+ years of experience in Web, Mobile and Application Development. Focused on .Net, Java, VB, SQL Server and related technologies as both a career and a personal passion

Comments and Discussions