I have a query that gets the sum of a field. I need to do 2 checks on it and am having to repeat the original query. I'm assuming the result is cached so it doesn't actually run 3 times but how can I tidy it up? I'd be inclined to use a varible but its tied to row we are in.What am I missing?SELECT UniqueId, (SELECT SUM(Capacity) FROM Seating_Group WHERE AreaId = Seating_Area.UniqueID AND UniqueId Not In ( SELECT * FROM dbo.GetOccupiedGroups(0,@StartDate,@EndDate) ) ) as Capacity FROM Seating_Area WHERE (SELECT SUM(Capacity) FROM Seating_Group WHERE AreaId = Seating_Area.UniqueID AND UniqueId Not In ( SELECT * FROM dbo.GetOccupiedGroups(0,@StartDate,@EndDate) ) ) is not null AND (SELECT SUM(Capacity) FROM Seating_Group WHERE AreaId = Seating_Area.UniqueID AND UniqueId Not In ( SELECT * FROM dbo.GetOccupiedGroups(0,@StartDate,@EndDate) ) ) >= @RequiredSeats