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 TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Can;t delete if inner join

Status
Not open for further replies.

TRACEYMARYLAND

Programmer
May 21, 2004
370
US
hi my select works but when change select to delete from
it errors on inner join


SELECT * FROM DATAWAREHOUSETEST.DBO.SHELTERPRODUCTS
INNER JOIN VMFG.DBO.WORK_ORDER ON DATAWAREHOUSETEST.DBO.SHELTERPRODUCTS.WORKORDER_BASE_ID = VMFG.DBO.WORK_ORDER.BASE_ID
WHERE VMFG.DBO.WORK_ORDER.STATUS IN ('F', 'R')

To

DELETE FROM DATAWAREHOUSETEST.DBO.SHELTERPRODUCTS
INNER JOIN VMFG.DBO.WORK_ORDER ON DATAWAREHOUSETEST.DBO.SHELTERPRODUCTS.WORKORDER_BASE_ID = VMFG.DBO.WORK_ORDER.BASE_ID
WHERE VMFG.DBO.WORK_ORDER.STATUS IN ('F', 'R')

Any one point me in the right direction
 
You need to explicity state which table you want to delete rows from.
Code:
[Blue]DELETE[/Blue] Table1
   [Blue]FROM[/Blue] Table1 [Blue]INNER[/Blue] [Gray]JOIN[/Gray] Table2
      [Blue]ON[/Blue] Table1.ID[Gray]=[/Gray]Table2ID
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Like so

DELETE DATAWAREHOUSETEST.DBO.SHELTERPRODUCTS
FROM DATAWAREHOUSETEST.DBO.SHELTERPRODUCTS INNER JOIN VMFG.DBO.WORK_ORDER
ON DATAWAREHOUSETEST.DBO.SHELTERPRODUCTS.WORKORDER_BASE_ID=VMFG.DBO.WORK_ORDER.BASE_ID
WHERE VMFG.DBO.WORK_ORDER.STATUS NOT IN ('F','R')

So before i run it the data will only be deleted from SHELTER PRODUCTS is that true

Cheers
 
As you should...I still do too.
-Karl

[red] Cursors, triggers, user-defined functions and dynamic SQL are an axis of evil![/red]
[green]Life's uncertain...eat dessert first...www.deerfieldbakery.com[/green]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top