I am not certain I am doing this correctly. I have many records being grouped together, and on another table there exist a due date for each one which vary, I just want to include the nearest due date.
This is my original query to display the grouped records:
SELECT Burning.PBurning, Burning.PlateTag, Plate.Crop, Plate.MachTime, SUM(CONVERT(INT, Burning.PQty)) AS SumPqty, SUM(CONVERT(INT, Burning.PQtyBrn)) AS SumPQtyBrn
FROM Burning, Plate
WHERE Burning.PMachine='Accukut' AND Burning.PlateTag = Plate.Tag GROUP BY PlateTag, PBurning, Crop, MachTime
Trying to get the nearest due date on another table by adding a left outer join:
SELECT Burning.PBurning, Burning.PlateTag, Plate.Crop, Plate.MachTime, SUM(CONVERT(INT, Burning.PQty)) AS SumPqty, SUM(CONVERT(INT, Burning.PQtyBrn)) AS SumPQtyBrn
FROM Burning, Plate
LEFT OUTER JOIN (SELECT Drawings.Job, Drawings.Series, Drawings.DwgDue FROM Drawings WHERE CONVERT(Date, SUBSTRING(Drawings.DwgDue,1,10), 103) <= CONVERT(Date, GETDATE(), 103) ) d ON Burning.PJob=Drawings.Job AND Burning.PSeries=Drawings.Series
WHERE Burning.PMachine='Accukut' AND Burning.PlateTag = Plate.Tag AND Burning.PJob = Drawings.Job AND Burning.PSeries = Drawings.Series GROUP BY PlateTag, PBurning, Crop, MachTime
I am getting continuous errors about columns not being bound, etc. I have a feeling I am not on the right track at all. Any advice appreciated!