MidlandChilled 3/9/2019 8:45:39 AM

Excluding Fields from Delete in a SQL Job

Hey all,

I would like to run a SQL Job every day which runs a SQL command which deletes from a table where records are 60 days older than LSTORDDT. I also want to exclude certain CUSTNMBR fields in TEMPLATES (the same as in RM00101) that I have setup in a new table.

Any new CUSTNMBR added to the new table gets excluded also.

I have a Table called 'EXCLUDE' with one column called 'DebtorID' (char15) which is populated by 4 records.

The Table I wish to delete the records from is called 'TEMPLATES'

If I create a SQL job with this code:

DELETE FROM dbo.TEMPLATES WHERE LSTORDDT < DATEADD(d,-60,GETDATE()) AND NOT EXISTS ( SELECT NULL FROM dbo.EXCLUDE m WHERE m.DebtorID = CUSTNMBR )
GO

Is this correct for a SQL Job?

Thanks

Version: All
Section: Dynamics GP


Table Definition Quick Links
All Tables
SOP Tables
RM Tables
GL Tables
POP Tables
HR Tables
PM Tables
UPR Tables
IV Tables
Olympic Tables
3