Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
zeeshan13
Constraint Violating Yak Guru
347 Posts |
Posted - 2009-10-09 : 08:14:40
|
| Hi All,I have a following simple stored procedure which delete records from 3 tables. I want the stored procedure to delete records from 3 tables only when it is a Friday. And if it is not a Friday do not do anything (do not delete any records). How to Modify my stored procedure with this change? Thanks in advance for the help.Zee--Start of Stored ProcedureCreate PROCEDURE [dbo].[z_DeleteLastImportedProm] @DateFrom Datetime=NULL ASBEGIN SET NOCOUNT ON; SET @DateFrom=CONVERT(VARCHAR(10),GETDATE()+2,120)--Step 1--Remove records from Table1 tableDELETE FROM Table1 WHERE ProductStatus=1 and SimulationSID is NULL and StartDate>=CONVERT(VARCHAR(10),@DateFrom,120)--Step 2--Remove records from Table2 tableDELETE FROM Table2 WHERE ProductStatus=1 and SimulationSID is NULL and StartDate>=CONVERT(VARCHAR(10),@DateFrom,120)--Step 3--Remove records from Table3 tableDELETE FROM Table3 WHERE SimulationSID is NULL and StartDate>=CONVERT(VARCHAR(10),@DateFrom,120)END--End of Stored Procedure |
|
|
madhivanan
Premature Yak Congratulator
22864 Posts |
Posted - 2009-10-09 : 08:17:37
|
| if datename(weekday,@DateFrom)='Friday' Begin--all your deletesEndMadhivananFailing to plan is Planning to fail |
 |
|
|
|
|
|