Sunday January 21st 2018

Categories

Insider

Archives

Crosstab report of quarterly debits by years

This is similar query with only 1 difference i.e accountid. It show same results by accountid grouping. It will help to analyze quarterly expenses by different accounts during 2004 and 2005.

select accountid, datepart(year, transactiondate) ‘year’,
sum(case datepart(quarter, transactiondate) when 1 then debit else 0 end)q1,
sum(case datepart(quarter, transactiondate) when 2 then debit else 0 end)q2,
sum(case datepart(quarter, transactiondate) when 3 then debit else 0 end)q3,
sum(case datepart(quarter, transactiondate) when 4 then debit else 0 end)q4
from transactions
where transactiondate > ‘2004′
group by accountid, datepart( year, transactiondate)
order by accountid, year asc

admin Sql Language
—————————————
Crosstab report of quarterly debits by years
December 29th, 2008 No comments select datepart(year, transactiondate) ‘year’,
sum(case datepart(quarter, transactiondate) when 1 then debit else 0 end)q1,
sum(case datepart(quarter, transactiondate) when 2 then debit else 0 end)q2,
sum(case datepart(quarter, transactiondate) when 3 then debit else 0 end)q3,
sum(case datepart(quarter, transactiondate) when 4 then debit else 0 end)q4
from transactions
where transactiondate > ‘2004′
group by datepart( year, transactiondate)

Result will look in a cross tab