0

Below is the section of code that is getting an error. I am not sure why I am getting an error.

Delete from TblProcessCurrency C
where Not Exists (
    Select PRCSchedule
    from tblProcess P 
    where P.PrcSchedule = C.PCXSchedule and P.PRCOlsn = C.PCXOlsn and P.PRCRelease = C.PCXRelease
);

and here is the error I am getting

Msg 102, Level 15, State 1, Line 32
Incorrect syntax near 'C'.

Dale K
  • 25,246
  • 15
  • 42
  • 71
NorSer
  • 134
  • 2
  • 13
  • 2
    Does this answer your question? [Why can't I use an alias in a DELETE statement?](https://stackoverflow.com/questions/11005209/why-cant-i-use-an-alias-in-a-delete-statement) – Isaac Mar 09 '20 at 22:10
  • If you want to a more intuitive `delete` statement, you may rewrite this using a `join`. Resource on that https://sqlstudies.com/2013/09/24/dba-myths-you-cant-use-an-alias-in-a-delete-statement/ – Radagast Mar 09 '20 at 22:41

1 Answers1

2

You want:

DELETE C
FROM TblProcessCurrency C 
WHERE Not Exists...

You can't alias the table that is the target for the DELETE, unless you state you want to DELETE from said alias.

Thom A
  • 88,727
  • 11
  • 45
  • 75