I am working with 4 tables. Two hold the data I need to pull (dbo_jodrtg and dbo_jomast), one is the table I need to insert that data into (Budgets), and one is a table that holds related data (Actuals), which I am referring to in the query entirely to limit what data is transferred into Budgets.
I need to pull only those items from the source tables in which the dbo_jomast.fsono field has a value that can be found somewhere in the Actuals.SalesOrder field.
The query works fine without limiting the data based on Actuals:
[tt]INSERT INTO Budgets ( SalesOrder, Job, WorkCtr, Dollars, Hours )
SELECT dbo_jomast.fsono, dbo_jodrtg.fjobno, dbo_jodrtg.fpro_id, Sum(dbo_jodrtg.fprod_val) AS SumOffprod_val, Sum(dbo_jodrtg.fprod_tim) AS SumOffprod_tim
FROM dbo_jomast INNER JOIN dbo_jodrtg ON dbo_jomast.fjobno = dbo_jodrtg.fjobno
GROUP BY dbo_jomast.fsono, dbo_jodrtg.fjobno, dbo_jodrtg.fpro_id
ORDER BY dbo_jomast.fsono, dbo_jodrtg.fjobno, dbo_jodrtg.fpro_id;
[/tt]
Below is the current code:
[tt]INSERT INTO Budgets ( SalesOrder, Job, WorkCtr, Dollars, Hours )
SELECT dbo_jomast.fsono, dbo_jodrtg.fjobno, dbo_jodrtg.fpro_id, Sum(dbo_jodrtg.fprod_val) AS SumOffprod_val, Sum(dbo_jodrtg.fprod_tim) AS SumOffprod_tim
FROM dbo_jomast WHERE dbo_jomast.fsono IN (SELECT Actuals.SalesOrder FROM Actuals)
INNER JOIN dbo_jodrtg ON dbo_jomast.fjobno = dbo_jodrtg.fjobno
GROUP BY dbo_jomast.fsono, dbo_jodrtg.fjobno, dbo_jodrtg.fpro_id
ORDER BY dbo_jomast.fsono, dbo_jodrtg.fjobno, dbo_jodrtg.fpro_id;[/tt]
With this code, I get an error that tells me there is a:
[tt]Syntax error (missing operator) in query expression 'dbo_jomast.fosono IN (SELECT Actuals.SalesOrder FROM Actuals) INNER JOIN dbo_jodrtg ON dbo_jomast.fjobno = dbo_jodrtg.fjobno'.
[/tt]
I tried putting the filter into the join, like so:
[tt]INSERT INTO Budgets ( SalesOrder, Job, WorkCtr, Dollars, Hours )
SELECT dbo_jomast.fsono, dbo_jodrtg.fjobno, dbo_jodrtg.fpro_id, Sum(dbo_jodrtg.fprod_val) AS SumOffprod_val, Sum(dbo_jodrtg.fprod_tim) AS SumOffprod_tim
FROM dbo_jomast
INNER JOIN dbo_jodrtg, Actuals ON dbo_jomast.fjobno = dbo_jodrtg.fjobno
AND dbo_jomast.fsono IN (SELECT Actuals.SalesOrder FROM Actuals)
GROUP BY dbo_jomast.fsono, dbo_jodrtg.fjobno, dbo_jodrtg.fpro_id
ORDER BY dbo_jomast.fsono, dbo_jodrtg.fjobno, dbo_jodrtg.fpro_id;[/tt]
It then tells me [tt]Syntax error in FROM clause.[/tt]
I'm not sure where or how to add this filter.
Cheryl dc Kern
I need to pull only those items from the source tables in which the dbo_jomast.fsono field has a value that can be found somewhere in the Actuals.SalesOrder field.
The query works fine without limiting the data based on Actuals:
[tt]INSERT INTO Budgets ( SalesOrder, Job, WorkCtr, Dollars, Hours )
SELECT dbo_jomast.fsono, dbo_jodrtg.fjobno, dbo_jodrtg.fpro_id, Sum(dbo_jodrtg.fprod_val) AS SumOffprod_val, Sum(dbo_jodrtg.fprod_tim) AS SumOffprod_tim
FROM dbo_jomast INNER JOIN dbo_jodrtg ON dbo_jomast.fjobno = dbo_jodrtg.fjobno
GROUP BY dbo_jomast.fsono, dbo_jodrtg.fjobno, dbo_jodrtg.fpro_id
ORDER BY dbo_jomast.fsono, dbo_jodrtg.fjobno, dbo_jodrtg.fpro_id;
[/tt]
Below is the current code:
[tt]INSERT INTO Budgets ( SalesOrder, Job, WorkCtr, Dollars, Hours )
SELECT dbo_jomast.fsono, dbo_jodrtg.fjobno, dbo_jodrtg.fpro_id, Sum(dbo_jodrtg.fprod_val) AS SumOffprod_val, Sum(dbo_jodrtg.fprod_tim) AS SumOffprod_tim
FROM dbo_jomast WHERE dbo_jomast.fsono IN (SELECT Actuals.SalesOrder FROM Actuals)
INNER JOIN dbo_jodrtg ON dbo_jomast.fjobno = dbo_jodrtg.fjobno
GROUP BY dbo_jomast.fsono, dbo_jodrtg.fjobno, dbo_jodrtg.fpro_id
ORDER BY dbo_jomast.fsono, dbo_jodrtg.fjobno, dbo_jodrtg.fpro_id;[/tt]
With this code, I get an error that tells me there is a:
[tt]Syntax error (missing operator) in query expression 'dbo_jomast.fosono IN (SELECT Actuals.SalesOrder FROM Actuals) INNER JOIN dbo_jodrtg ON dbo_jomast.fjobno = dbo_jodrtg.fjobno'.
[/tt]
I tried putting the filter into the join, like so:
[tt]INSERT INTO Budgets ( SalesOrder, Job, WorkCtr, Dollars, Hours )
SELECT dbo_jomast.fsono, dbo_jodrtg.fjobno, dbo_jodrtg.fpro_id, Sum(dbo_jodrtg.fprod_val) AS SumOffprod_val, Sum(dbo_jodrtg.fprod_tim) AS SumOffprod_tim
FROM dbo_jomast
INNER JOIN dbo_jodrtg, Actuals ON dbo_jomast.fjobno = dbo_jodrtg.fjobno
AND dbo_jomast.fsono IN (SELECT Actuals.SalesOrder FROM Actuals)
GROUP BY dbo_jomast.fsono, dbo_jodrtg.fjobno, dbo_jodrtg.fpro_id
ORDER BY dbo_jomast.fsono, dbo_jodrtg.fjobno, dbo_jodrtg.fpro_id;[/tt]
It then tells me [tt]Syntax error in FROM clause.[/tt]
I'm not sure where or how to add this filter.
Cheryl dc Kern