Trying to format Query

Hello,

select Curr.Branch, Curr.AcctType,(Curr.ABal-Prev.ABal) Change
FROM
(
select Account.AcctType ATID, AcctDesc.AcctType, B.Branch, sum(AcctBalance) ABal
from Savings1 Account
left join Branches B
ON Account.BranchID=B.BranchID
left join (select FDD_FIELD_VALUE AcctTypeID, FDD_DESCR_32 AcctType
FROM MiserFieldXRef.dbo.FieldDescription Mise
where FDD_master_field like ‘%s-acct-type%’) AcctDesc
ON Account.AcctType=AcctDesc.AcctTypeID
where [Status]<3
group by Account.AcctType, AcctDesc.AcctType, B.Branch
) Curr
join
(
select Account.AcctType ATID, AcctDesc.AcctType, B.Branch, sum(AcctBalance) ABal
from Savings2 Account
left join Branches B
ON Account.BranchID=B.BranchID
left join (select FDD_FIELD_VALUE AcctTypeID, FDD_DESCR_32 AcctType
FROM MiserFieldXRef.dbo.FieldDescription Mise
where FDD_master_field like ‘%s-acct-type%’) AcctDesc
ON Account.AcctType=AcctDesc.AcctTypeID
where [Status]<3
group by Account.AcctType, AcctDesc.AcctType, B.Branch
) Prev
ON Curr.Branch=Prev.Branch and Curr.ATID=Prev.ATID
order by Curr.Branch, Curr.AcctType

The query above displays this result set

Branch AcctType Change ($)


Georgia Personal Checking 2154789
Georgia Savings 2455555
Georgia Money Market 124545
Florida Personal Checking 132323
Florida Savings 458744
Florida Money Market 2547888
Florida 6-8mnts CD 12455446

I need the results of the query above to create a report in SSRS that looks like what I have below.

Account Type Georgia Florida


Personal Checking 2154789 132323
Savings 2455555 458744
Money Market 124545 2547888
6-8mnts CD 12455446

Any ideas on how I can reformat the query given to me from the format above to the format below? All suggestions welcome, I am new to writing queries and SSRS in general.

Sorry, didn’t have time to go through your code, and it’s not easily read formatting wise, but this might help you get to what you want in the end. My code is SQL2005 where the #ALLCUSTSTMP is a temporary cursor table. We still end up going into one more cursor to make sure it groups with some other data but this creates the fields for a columnar style result that you’re looking for.

[SIZE=“2”]-- MAke cursor with totals by columns
Select #ALLCUSTSTMP.MainCOPK, --CUSTID
#ALLCUSTSTMP.MainName,
#ALLCUSTSTMP.ShipName,
#ALLCUSTSTMP.ShipSt,
#ALLCUSTSTMP.COstatePSPK, --StatePK
#ALLCUSTSTMP.BillCOPK, --BillCustID
#ALLCUSTSTMP.BillCOMP,
#ALLCUSTSTMP.BillType,
#ALLCUSTSTMP.MainBizzPK, --BizzClass

--PREVIOUS YEARS TOTALS
	isnull(GEPrevYR.PYRCuttings,0) as PYGeCuts,	--Bizz1
	isnull(FFPrevYR.PYRCuttings,0) as PYFFCuts,	--Bizz2
	isnull(PTPrevYR.PYRCuttings,0) as PYPinCuts,	--Bizz3
--CURRENT YEARS TOTALS	
	isnull(GECurrYR.CYRCuttings,0) as CYGeCuts,	--Bizz1
	isnull(FFCurrYR.CYRCuttings,0) as CYFFCuts,	--Bizz2
	isnull(PTCurrYR.CYRCuttings,0) as CYPinCuts	--Bizz3

from #ALLCUSTSTMP
— Bizz1 LINKAGE Previous Year
LEFT OUTER JOIN #SubNetFigs1TMPPrev as GEPrevYR
on #ALLCUSTSTMP.MainCOPK = GEPrevYR.MainCOPK
and #ALLCUSTSTMP.BillCOPK = GEPrevYR.BillCOPK
and #ALLCUSTSTMP.ShipName = GEPrevYR.ShipName
and #ALLCUSTSTMP.ShipSt = GEPrevYR.ShipSt
and #ALLCUSTSTMP.COstatePSPK = GEPrevYR.COstatePSPK
and #ALLCUSTSTMP.BillType = GEPrevYR.BillType
and #ALLCUSTSTMP.MainBizzPK = GEPrevYR.MainBizzPK
and GEPrevYR.MainBizzPK = 5209

--Bizz1 Linkage Current Year	

LEFT OUTER JOIN #SubNetFigs1TMPCurr as GECurrYR
on #ALLCUSTSTMP.MainCOPK = GECurrYR.MainCOPK
and #ALLCUSTSTMP.BillCOPK = GECurrYR.BillCOPK
and #ALLCUSTSTMP.ShipName = GECurrYR.ShipName
and #ALLCUSTSTMP.ShipSt = GECurrYR.ShipSt
and #ALLCUSTSTMP.COstatePSPK = GECurrYR.COstatePSPK
and #ALLCUSTSTMP.BillType = GECurrYR.BillType
and #ALLCUSTSTMP.MainBizzPK = GECurrYR.MainBizzPK
and GECurrYR.MainBizzPK = 5209
------ And so on for the other Bizz colummns[/SIZE]

Good Luck. :wink: