I am trying to insert a row of data from one table where it does not exist in another table using the below statement.
In this case, I want to insert the data from table A into table B where week 4 in table B does not exist. And at the same time I am setting the week in table B to be 4. I get this to work but it brings in too much data and inserts rows for data that is should not. Any help here is appreciated.
Thanks
INSERT
INTO tbl_Plan_1_Test
(month,division, product_line,plan_numbers,monthname,week)
SELECT
tbl_plan_Test.month, tbl_plan_Test.division,prod_line,total,month_final,[week]=4
FROM tbl_plan_test,tbl_Plan_1_test
WHERE (tbl_plan_Test.division=tbl_plan_1_Test.division)
and (tbl_plan_Test.prod_line=tbl_plan_1_Test.product_Line)
and tbl_plan_Test.month_final = tbl_plan_1_Test.monthname
and tbl_plan_Test.month= tbl_plan_1_Test.month
and tbl_plan_1_Test.plan_numbers =tbl_plan_Test.total
and (tbl_plan_1_test.[week]) <> 4
In this case, I want to insert the data from table A into table B where week 4 in table B does not exist. And at the same time I am setting the week in table B to be 4. I get this to work but it brings in too much data and inserts rows for data that is should not. Any help here is appreciated.
Thanks
INSERT
INTO tbl_Plan_1_Test
(month,division, product_line,plan_numbers,monthname,week)
SELECT
tbl_plan_Test.month, tbl_plan_Test.division,prod_line,total,month_final,[week]=4
FROM tbl_plan_test,tbl_Plan_1_test
WHERE (tbl_plan_Test.division=tbl_plan_1_Test.division)
and (tbl_plan_Test.prod_line=tbl_plan_1_Test.product_Line)
and tbl_plan_Test.month_final = tbl_plan_1_Test.monthname
and tbl_plan_Test.month= tbl_plan_1_Test.month
and tbl_plan_1_Test.plan_numbers =tbl_plan_Test.total
and (tbl_plan_1_test.[week]) <> 4