Using Pivot In SQL for Reporting





0/5 (0 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