Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Some fancy SQL for TIP Amendment
Message
From
27/08/2013 17:44:45
 
 
To
All
General information
Forum:
Microsoft SQL Server
Category:
SQL syntax
Title:
Some fancy SQL for TIP Amendment
Environment versions
SQL Server:
SQL Server 6.5 and older
Application:
Web
Miscellaneous
Thread ID:
01581564
Message ID:
01581564
Views:
73
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.
Next
Reply
Map
View

Click here to load this message in the networking platform