I'm unfortunately dealing with someone else's code here, but needing a little push.
What I have happening is that I have a CTE that is needed to run in a nested join.
...Start of CTE INNER JOIN ( ;WITH FixedQty AS ( SELECT CASE WHEN WeekJobStartDate < @BegRange THEN SUM(WipJobQty) * -1 ELSE SUM(WipJobQty) END AS FixedAllocationQty ,StockCode ,WeekJobStartDate FROM [vwWipDet] WHERE WeekJobStartDate <= @EndRange GROUP BY StockCode, WeekJobStartDate ) SELECT SUM(FixedAllocationQty) AS WipJobQty ,StockCode FROM FixedQty GROUP BY StockCode ) AS WipDet ON InvMaster.StockCode = WipDet.StockCode ...
I've tried removing the semi-colon in front of the CTE, but then get a syntax error stating it is expecting that the previous statement must be terminated with a semi-colon.
I beating my head against the keyboard on this one.