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.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Delete records on Firday only

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 Procedure

Create PROCEDURE [dbo].[z_DeleteLastImportedProm]
@DateFrom Datetime=NULL

AS
BEGIN

SET NOCOUNT ON;
SET @DateFrom=CONVERT(VARCHAR(10),GETDATE()+2,120)

--Step 1
--Remove records from Table1 table
DELETE FROM Table1
WHERE ProductStatus=1 and SimulationSID is NULL
and StartDate>=CONVERT(VARCHAR(10),@DateFrom,120)

--Step 2
--Remove records from Table2 table
DELETE FROM Table2
WHERE ProductStatus=1 and SimulationSID is NULL
and StartDate>=CONVERT(VARCHAR(10),@DateFrom,120)

--Step 3
--Remove records from Table3 table
DELETE 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 deletes
End

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -