Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

Using Pivot In SQL for Reporting

, 15 Mar 2011
Rate this:
Please Sign up or sign in to vote.
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
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 

License

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

About the Author

Kannan K R
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
Follow on   Twitter   Google+

Comments and Discussions

 
GeneralTry this http://www.codeproject.com/KB/database/Cross-Tabs-... PinmemberKannan K R14-Mar-11 23:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web03 | 2.8.140721.1 | Last Updated 15 Mar 2011
Article Copyright 2011 by Kannan K R
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid