Hello,
I am trying to amalgimate two queries using the EXISTS function, but i have run into a few problems.
Basically, i don't know how to reference the fields that were originally calculated in the first query.
The problems are with the following elements of the query, all of which had alias's created, but are no longer recognised:
[A].CountOfMeterPointRef) AS Meters
Sum( [A].AnnualRevenue) AS ConsumptionRevenue
Sum( [A].annualstandingCharge) AS AnnualStandingCharge
Sum( [A].TotalRevenue) AS SumOfTotalRevenue
All suggestions will be very much appreciated
OOch
I am trying to amalgimate two queries using the EXISTS function, but i have run into a few problems.
Basically, i don't know how to reference the fields that were originally calculated in the first query.
The problems are with the following elements of the query, all of which had alias's created, but are no longer recognised:
[A].CountOfMeterPointRef) AS Meters
Sum( [A].AnnualRevenue) AS ConsumptionRevenue
Sum( [A].annualstandingCharge) AS AnnualStandingCharge
Sum( [A].TotalRevenue) AS SumOfTotalRevenue
Code:
SELECT TOP 50 [A].[Group ref], [A].[Group Name], Count( [A].SiteRefNum) AS CountOfSiteRefNum, Sum( [A].CountOfMeterPointRef) AS Meters, [A].[Site status], Sum(([Site AQ])/1000000) AS [TotalConsumption(GWh)], Sum( [A].AnnualRevenue) AS ConsumptionRevenue, Sum( [A].annualstandingCharge) AS AnnualStandingCharge, Sum( [A].TotalRevenue) AS SumOfTotalRevenue
FROM [002-NBS_GAS_ROOTDATA_20040923]
WHERE EXISTS
(SELECT [B].[Site status], [B].[Group ref], [B].[Group Name], [B].SiteRefNum, Count([B].MeterPointRef) AS CountOfMeterPointRef, [B].[Site AQ], (([B]![Site AQ]*([B]![Price]))/100) AS AnnualRevenue, 365*Sum(([standingcharge])) AS annualstandingCharge, (([B]![Site AQ]*([B]![Price]))+(365*Sum([standingcharge])))/100 AS TotalRevenue
FROM [002-NBS_GAS_ROOTDATA_20040923] as [B]
GROUP BY [B].[Site status], [B].[Group ref], [B].[Group Name], [B].SiteRefNum, [B].[Site AQ], [B]![Site AQ]*[B]![Price]
HAVING ((([B].[Site status]) Not Like "*lost*" And ([B].[Site status]) Not Like "*inactive*"))
ORDER BY (([B]![Site AQ]*([B]![Price]))+(365*Sum([standingcharge])))/100 DESC)
GROUP BY [A].[Group ref], [A].[Group Name], [A].[Site status]
HAVING ((( [A].[Group ref]) Not Like 0))
ORDER BY Sum( [A].TotalRevenue) DESC
;
All suggestions will be very much appreciated
OOch