Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Combining results from multiple tables in TIP
Message
De
05/08/2014 17:42:45
 
 
À
Tous
Information générale
Forum:
Microsoft SQL Server
Catégorie:
Syntaxe SQL
Titre:
Combining results from multiple tables in TIP
Versions des environnements
SQL Server:
SQL Server 2014
Application:
Web
Divers
Thread ID:
01605208
Message ID:
01605208
Vues:
31
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform