Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with an Insert and Where statement

Status
Not open for further replies.

gaperry

IS-IT--Management
Jan 29, 2002
37
0
0
US
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
 
Not knowing about your table design I guess that you need a condition like

and tbl_plan_test.[week] = 4
 
swampBoogie, thanks for the reply. The tables I am using have very few fields. What I am trying to do is:

In table B, I need to add a week number in the week field, (in this case week number 4) where it does not exist and at the same time, update the other fields that go with week 4 in table B, with the matching fields in table A.

Hope I am not making this to confusing.

Thanks



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top