Connecting Tech Pros Worldwide Help | Site Map

strange sql error msg

n8kindt's Avatar
Familiar Sight
 
Join Date: Mar 2008
Location: Southern California
Posts: 221
#1: May 9 '08
here's my sql code:

Expand|Select|Wrap|Line Numbers
  1. SELECT ActivityLog.DateSignedIN, Sum(ActivityLog.ProductPurchased) AS SumOfProductPurchased, Sum(ActivityLog.ProductAdj) AS SumOfProductAdj, Sum(ActivityLog.TaxPercent) AS SumOfTaxPercent, Sum(ActivityLog.Subtotal) AS SumOfSubtotal, Sum(ActivityLog.GrandTotal) AS SumOfGrandTotal, Sum(ActivityLog.TransactionType) AS SumOfTransactionType, Sum(Round((((([ProductPurchased] + Nz([ProductAdj],0))*([TaxPercent]*2)) + (([Subtotal]-([ProductPurchased] + Nz([ProductAdj],0)))*[TaxPercent]) + [Subtotal])+Nz([Shipping],0))+0.000001,2)) AS ExpectedGrandTotal, Sum(Round(Nz([GrandTotal],[ExpectedGrandTotal]),2)) AS FinalGT, Sum(ActivityLog.Shipping) AS SumOfShipping, Sum(Round((([TaxPercent]*([Subtotal] - ([ProductPurchased] + Nz([ProductAdj],0)))) + (2*([ProductPurchased] + Nz([ProductAdj],0))*[TaxPercent]) + 0.00000001),2)) AS ExpectedTax, Sum(ActivityLog.ActualTax) AS SumOfActualTax, Sum(Round(Nz([ActualTax],[ExpectedTax]),2)) AS FinalTax, Sum([subtotal]-[productpurchased]) AS Supplies
  2. FROM ActivityLog
  3. WHERE (((Month([DateSignedIN]))=[Forms]![frmDRInput]![Month]) AND ((Year([DateSignedIN]))=[Forms]![frmDRInput]![Year]))
  4. GROUP BY ActivityLog.DateSignedIN;
Here's the error msg:
Subqueries cannot be used in the expression (Round(Nz([GrandTotal],[ExpectedGrandTotal]),2)).

if i hide the 'FinalGT' and the 'ExpectedTax' columns (FinalGT is the one with the troublesome code--i have to hide ExpectedTax, too b/c it returns a similar error msg), it runs fine.... which is wierd b/c 'ExpectedGT' and 'FinalGT' use the same format but they run fine... uhhhh why am i getting this error msg???
nico5038's Avatar
Moderator
 
Join Date: Nov 2006
Location: The Netherlands
Posts: 2,232
#2: May 9 '08

re: strange sql error msg


I'm afraid you can't use the "as" fields in the same query. You would have to replace them by the calculation used to create them.
An alternative is to save the query without this field and use the saved query in a new query where you place the calculation.

Nic;o)
n8kindt's Avatar
Familiar Sight
 
Join Date: Mar 2008
Location: Southern California
Posts: 221
#3: May 9 '08

re: strange sql error msg


Quote:

Originally Posted by nico5038

I'm afraid you can't use the "as" fields in the same query. You would have to replace them by the calculation used to create them.
An alternative is to save the query without this field and use the saved query in a new query where you place the calculation.

Nic;o)

that makes sense. thanks nico!
Reply


Similar Microsoft Access / VBA bytes