|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Find date difference and delete record
I want to delete the records who older than 90 days. This code is not
working.Can anyone help please? create PROCEDURE dbo.deleteReservation @resID int, @d int, @diff int as set nocount on Declare CurRes CURSOR for SELECT DATEDIFF(d,reservationdate, getdate()),id from reservations OPEN CurRes FETCH NEXT FROM CurRes INTO @diff,@resID WHILE @@FETCH_STATUS = 0 BEGIN IF @diff > 1 BEGIN EXEC('DELETE FROM reservations WHERE id =' + @resID) End FETCH NEXT FROM CurRes INTO @diff,@resID END CLOSE CurRes DEALLOCATE CurRes go |
|
#2
|
||||
|
||||
|
hmmm... that seems a very complicated way of doing things...
here is my suggestion Code:
create procedure dbo.deleteDates as delete from yourTable where dateDiff(d, oldDate, newDate)>90 hope this helps BTW what is the result of your code? does it delete everything? or does it throw an error message. |
|
#3
|
|||
|
|||
|
Thanks for the suggestion. Now my code is working
properly. Here is the code. CREATE PROCEDURE dbo.dt_UpdateReservation_resStatus AS Declare @s_resID integer Declare @s_diff integer Declare CurRes CURSOR for SELECT DATEDIFF(d,createdon,getdate()),id from reservations where is_reservation=0 OPEN CurRes FETCH NEXT FROM CurRes INTO @s_diff,@s_resID WHILE @@FETCH_STATUS = 0 BEGIN IF @s_diff = 1 BEGIN EXEC('Update reservations set reservationstatus=8 where id =' + @s_resID) End FETCH NEXT FROM CurRes INTO @s_diff,@s_resID END CLOSE CurRes DEALLOCATE CurRes GO |
![]() |
| Viewing: ASP Free Forums > Database > Microsoft SQL Server > Find date difference and delete record |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|