I have 2 queries that I need to combine into 1. Both queries group on the following Saturday of a datetime column in different tables. I need to join the queries on the grouped column. My following SQL gives me the following error, which is probably some sort of syntax problem:Server: Msg 207, Level 16, State 3, Line 5Invalid column name 'WQEndWeekDate'.USE ChemWatchDECLARE @CustNo intSET @CustNo = 12186SELECT DateAdd(day, -2, DateAdd(week, DateDiff(week, 0,WeightQuery.BOF_Date)+1, 0)) AS WQEndWeekDate, SUM(WeightQuery.LF_WT_Target) AS Target_WT, SUM(WeightQuery.Actual_WT) AS Actual_WT, SUM(MeterQuery.CwebQty) AS CWebQty, SUM(MeterQuery.CustQty) AS CustQtyFROM Washrun AS WeightQueryLEFT JOIN ( SELECT DateAdd(day, -2, DateAdd(week, DateDiff(week, 0, [TimeStamp])+1, 0)) AS MDEndWeekDate, Meters.MeterType, Meters.SubType, MeterData.CustQty, MeterData.CWebQTY FROM MeterData INNER Join Meters ON Meters.Customer_No = MeterData.Customer_No AND Meters.MeterID = MeterData.MeterID WHERE MeterData.Customer_No = @CustNo AND MeterData.TimeStamp Between '10/30/2005' AND '12/04/2005' AND Meters.cWebReports = 1 )AS MeterQueryON MeterQuery.MDEndWeekDate = WeightQuery.WQEndWeekDateWHERE WeightQuery.Customer_No = @CustNo AND WeightQuery.BOF_DATE Between '10/30/2005' AND '12/04/2005' AND (WeightQuery.EOF_Date > WeightQuery.BOF_Date OR WeightQuery.Actual_WT > 0)GROUP BY DateAdd(day, -2, DateAdd(week, DateDiff(week, 0,WeightQuery.BOF_Date)+1, 0))ORDER BY 1
If you know of a sample of how to do this in BOL, please let me know.TIA,