MS Access Query to SQL Server Transform And Pivots -
i need convert access query sql sever query.
qry_budgetfortwelvemonths :
select t.jobid, t.accountid, t.financialyear finyear, t.period, sum(t.amount) amt (select jobid, accountid,financialyear, period, amount temp_blankbudgets union select jobid, accountid,financialyear, period, amount temp_budgets) t group t.jobid, t.accountid, t.period, t.financialyear order t.jobid, t.accountid, t.period;
qry_crstabjobbudgetfortwelvemonths :
transform sum(qry_budgetfortwelvemonths.amt) sumofamt select qry_budgetfortwelvemonths.jobid, qry_budgetfortwelvemonths.accountid, qry_budgetfortwelvemonths.finyear, sum(qry_budgetfortwelvemonths.amt) fytotal qry_budgetfortwelvemonths group qry_budgetfortwelvemonths.jobid, qry_budgetfortwelvemonths.accountid, qry_budgetfortwelvemonths.finyear pivot qry_budgetfortwelvemonths.period;
final query
select temp_accounts.accountnumber, temp_accounts.accountname,qry_crstabjobbudgetfortwelvemonths.[1],qry_crstabjobbudgetfortwelvemonths.[2], qry_crstabjobbudgetfortwelvemonths.[3],qry_crstabjobbudgetfortwelvemonths.[4], qry_crstabjobbudgetfortwelvemonths.[5], qry_crstabjobbudgetfortwelvemonths.[6], qry_crstabjobbudgetfortwelvemonths.[7], qry_crstabjobbudgetfortwelvemonths.[8], qry_crstabjobbudgetfortwelvemonths.[9], qry_crstabjobbudgetfortwelvemonths.[10], qry_crstabjobbudgetfortwelvemonths.[11], qry_crstabjobbudgetfortwelvemonths.[12], temp_accounts.accountid,qry_crstabjobbudgetfortwelvemonths.fytotal temp_accounts inner join qry_crstabjobbudgetfortwelvemonths on temp_accounts.accountid = qry_crstabjobbudgetfortwelvemonths.accountid
here's take:
--qry_budgetfortwelvemonths : select t.jobid , t.accountid , t.financialyear finyear , t.period , sum(t.amount) amt #tmp1 (select jobid , accountid ,financialyear , period , amount temp_blankbudgets union select jobid , accountid ,financialyear , period , amount temp_budgets) t group t.jobid, t.accountid, t.period, t.financialyear order t.jobid, t.accountid, t.period; --qry_crstabjobbudgetfortwelvemonths : select * #tmp2 ( select a.jobid , a.accountid , a.financialyear , sum(a.amount) fytotal #tmp group a.jobid, a.accountid, a.financialyear ) source pivot ( sum(a.amount) sumofamt bmonth in ([1],[2],[3],[4],[5],[6],[7],[8],[9],[10],[11],[12]) ) pvt order bmonth --final query select temp_accounts.accountnumber , temp_accounts.accountname , b.[1] , b.[2] , b.[3] , b.[4] , b.[5] , b.[6] , b.[7] , b.[8] , b.[9] , b.[10] , b.[11] , b.[12] , temp_accounts.accountid , b.fytotal temp_accounts inner join #tmp2 b on temp_accounts.accountid = b.accountid
Comments
Post a Comment