May 13, 2004 at 4:37 am
Line 29: Incorrect syntax near 'sp_dropdevice'.
Server: Msg 170, Level 15, State 1, Line 1
Line 1: Incorrect syntax near ','.
use master
--Declare Variables
SET NOCOUNT ON
DECLARE @DeviceName varchar(255)
DECLARE @File varchar(255)
DECLARE @Creation varchar(255)
DECLARE @OldPlus varchar(255)
DECLARE bud CURSOR FOR
SELECT BackupDeviceName,
BackupDeviceFile,
BackupDeviceCreation
FROM BackupDevice
-- Open the cursor
OPEN bud
-- Loop through the cursor
FETCH NEXT
FROM bud
INTO @DeviceName,
@File,
@Creation
WHILE @@FETCH_STATUS = 0
BEGIN
SET @OldPlus = DATEADD(day,7,@Creation)
IF @OldPlus < @Creation
BEGIN
sp_dropdevice @DeviceName,'DELFILE'
GO
DELETE BackupDeviceName,
BackupDeviceFile,
BackupDeviceCreation
FROM BackupDevice
WHERE BackupDeviceName = @DeviceName AND
BackupDeviceFile = @File AND
BackupDeviceCreation = @Creation
END
END
CLOSE bud
DEALLOCATE bud
May 13, 2004 at 5:04 am
Try changing sp_dropdevice @DeviceName,'DELFILE'
to
execute sp_dropdevice @DeviceName,'DELFILE'
/Kenneth
May 17, 2004 at 5:40 am
use master
--Declare Variables
DECLARE @DeviceName varchar(255)
DECLARE @File varchar(255)
DECLARE @Creation datetime
DECLARE @OldPlus datetime
-- Declare the cursor
DECLARE bud CURSOR FOR
SELECT BackupDeviceName, BackupDeviceFile, BackupDeviceCreation
FROM BackupDevice
ORDER BY BackupDeviceCreation
-- Open the cursor
OPEN bud
-- Loop through the cursor
FETCH NEXT FROM bud
INTO @DeviceName, @File, @Creation
WHILE @@FETCH_STATUS = 0
BEGIN
SET @OldPlus = DATEADD(day, 7, @Creation)
IF convert(varchar(50), @OldPlus, 101) <= convert(varchar(50),getdate(),101)
BEGIN
EXEC sp_dropdevice @DeviceName, DELFILE
DELETE FROM BackupDevice
WHERE BackupDeviceName = @DeviceName AND BackupDeviceFile = @File AND BackupDeviceCreation = @Creation
END
FETCH NEXT FROM bud
INTO @DeviceName, @File, @Creation
END
CLOSE bud
DEALLOCATE bud
May 22, 2005 at 5:32 am
what about the physical file??? i dont see any action to delete it?? what will happens when the DBbackups fill the HD??
May 23, 2005 at 3:33 am
To see the answer to that question, please open up BOL and search for 'sp_dropdevice'
/Kenneth
May 23, 2005 at 4:45 am
thanks for the reply my bad
May 23, 2005 at 5:05 am
No problems.
It's just that many forget how good BOL is, so I use to redirect there rather than just state the answers. In BOL you can most of the times not only read how, but also why stuff is like stuff is.
/Kenneth
Viewing 7 posts - 1 through 6 (of 6 total)
You must be logged in to reply to this topic. Login to reply