HiI'm trying to get a total for amounts that will come from a subquery.I'm getting multiple errors and I've tried multiple places for the SUM function butI'm quite lost now.Thank youMy code:SELECT SUM(Amount=ABS((SELECT Top 1 Amount+VATAmount FROM FAAccKitty WITH(NOLOCK) Where FAAccKitty.PlaceID=FAAccWinners.PlaceID AND FAAccKitty.TransType='PZ')))FROM FAAccWinners INNER JOIN Reservations WITH(NOLOCK) ON (Reservations.PlaceID = FAAccWinners.PlaceID) INNER JOIN Visitor WITH(NOLOCK) ON (Reservations.EMail = Visitor.EMail) WHERE FAAccWinners.Comments_Approved='Yes' AND FAAccWinners.PlaceID IN (SELECT PlaceID FROM FAAccKitty WITH(NOLOCK) Where FAAccKitty.PlaceID=FAAccWinners.PlaceID AND FAAccKitty.TransType='PZ' AND Year(TransDate)>1900 AND FAAccKitty.Approved='Yes') AND FAAccWinners.PlaceID NOT IN (SELECT PlaceID FROM FAAccKitty WITH(NOLOCK) Where FAAccKitty.PlaceID=FAAccWinners.PlaceID AND TransType='PC') AND Visitor.VisitorID= 274
Also tried:SELECT SUM(ABS((SELECT Top 1 Amount+VATAmount FROM FAAccKitty WITH(NOLOCK) Where FAAccKitty.PlaceID=FAAccWinners.PlaceID AND FAAccKitty.TransType='PZ')))FROM FAAccWinners INNER JOIN Reservations WITH(NOLOCK) ON (Reservations.PlaceID = FAAccWinners.PlaceID) INNER JOIN Visitor WITH(NOLOCK) ON (Reservations.EMail = Visitor.EMail) WHERE FAAccWinners.Comments_Approved='Yes' AND FAAccWinners.PlaceID IN (SELECT PlaceID FROM FAAccKitty WITH(NOLOCK) Where FAAccKitty.PlaceID=FAAccWinners.PlaceID AND FAAccKitty.TransType='PZ' AND Year(TransDate)>1900 AND FAAccKitty.Approved='Yes') AND FAAccWinners.PlaceID NOT IN (SELECT PlaceID FROM FAAccKitty WITH(NOLOCK) Where FAAccKitty.PlaceID=FAAccWinners.PlaceID AND TransType='PC') AND Visitor.VisitorID= 274
Tried this as well:SELECT Amount=ABS((SUM(SELECT Top 1 Amount+VATAmount FROM FAAccKitty WITH(NOLOCK) Where FAAccKitty.PlaceID=FAAccWinners.PlaceID AND FAAccKitty.TransType='PZ')))FROM FAAccWinners INNER JOIN Reservations WITH(NOLOCK) ON (Reservations.PlaceID = FAAccWinners.PlaceID) INNER JOIN Visitor WITH(NOLOCK) ON (Reservations.EMail = Visitor.EMail) WHERE FAAccWinners.Comments_Approved='Yes' AND FAAccWinners.PlaceID IN (SELECT PlaceID FROM FAAccKitty WITH(NOLOCK) Where FAAccKitty.PlaceID=FAAccWinners.PlaceID AND FAAccKitty.TransType='PZ' AND Year(TransDate)>1900 AND FAAccKitty.Approved='Yes') AND FAAccWinners.PlaceID NOT IN (SELECT PlaceID FROM FAAccKitty WITH(NOLOCK) Where FAAccKitty.PlaceID=FAAccWinners.PlaceID AND TransType='PC') AND Visitor.VisitorID= 274
Any help will be greatly appreciatedGreatness... Live It!!