Hi guys, I am new to stored procedures and have tried to get stuck into this task, but I am completely stuck.
What is required?
The object will be run as part of the nightly batch and will delete records from the interfacelog table. It will keep the number of records as specified in the parameters. If the parameters are less than 7, they will get reset to 7 to ensure there is always one week’s worth of historical data kept.
DELETE FROM interfacelog
WHERE datetime < (current timestamp – N days)
AND status = 1
The procedure will run as follows:
1. Check that the number of successful days is less than 7, if not set to 7, if greater than 7 set the variable to the parameter.
2. Delete the successful records from the table
3. Check that the number of failed days is less than 7, if not set to 7, if greater than 7 set the variable to the parameter.
4. Delete the failed records from the table.
With regards to the above, records are inserted in a table that I am using. The table will get very large and requires to be truncated on a regular basis.
Two parameters include - specify how many days worth of successful records which is 'Status 1', 2ND parameter specify how many days worth of failed records which is 'status 2'
Status is a field within the table i am using.
I have two input variables known as IN @success and IN @fail, both decimal data types.
I really hope you guys could help me out.
Thank you in advance
Ram