Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Combining results from multiple tables in TIP
Message
From
05/08/2014 17:42:45
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Combining results from multiple tables in TIP
Environment versions
SQL Server:
SQL Server 2014
Application:
Web
Miscellaneous
Thread ID:
01605208
Message ID:
01605208
Views:
32
I should know how to do this but today my mind is blank. Can someone help please?
Here are 4 queries:
select sum(amount) as igabudget, fundtype, phase from RTA_IGABudgets where TipID=@TipID group by Fundtype, phase
 
select sum(amount) as expended,  fundtype, phase from TIP_Ledger2 where TipID=@TipID and fisyear<@Tipyear group by FundType, phase

select sum(amount)*1000 as programmed, fundtype, phase from TIP_ApprovedFunding where TipID=@TipID and year<=@tipyear group by fundtype, phase 

select SUM(amount)*1000 as futureprogrammed, fundtype, phase from TIP_ApprovedFunding where TipID=@TipID and YEAR>@Tipyear group by FundType, PHASE
I want to combine the results of these into a single table with one row for each combination of Fundtype & Phase. So the result table has the columns
IGABudget
FundType
Phase
Programmed
FutureProgrammed

I have tries various combinations of JOINS, UNIONS, and DISTINCTS, but I can't seem to get it right. The problem is that not all combinations of fundtype and phase exist in all the tables. So we first have to pull those out and then do the math that goes with them.

Thanks
Next
Reply
Map
View

Click here to load this message in the networking platform