Information générale
Forum:
Microsoft SQL Server
Titre:
Some fancy SQL for TIP Amendment
Versions des environnements
SQL Server:
SQL Server 6.5 and older
Hi -
I'm not sure if this is possible but thought I would at least ask. There are 2 tables [Approved] and [Proposed]. They are identical in structure:
ProjectID, Amount, Fundtype. The number of possible fundtype values is unknown. We want to create a SELECT statement that will display the difference between the two tables with each fundtype being displayed as a column. Something like this:
Project | Fundtype1 | Fundtype2 | Fundtype3 | Fundtype4, etc.
P1 | 0 | 14 | 0 | -6 |
P2 | 5 | -2 | 8 | -1 |
In this example P1 has the same amount of Fundtype1 in both tables, so the difference is 0. It also has 14 more of Fundtype2 in [Proposed] than in [Approved], so the difference is 14 (Proposed minus Approved). and so on. P1 does not have Fundtype3 in either of the two tables. etc. I could build this result table programmatically with a loop and a lot of selects but I was wondering if there is a way to do it all in one select.
Thanks for any suggestions.
Suivant
Répondre
Voir le fil de ce thread
Voir le fil de ce thread à partir de ce message seulement
Voir tous les messages de ce thread
Voir tous les messages de ce thread à partir de ce message seulement