HiI run the following code to restore my LIVE DATA to DEV overnight.The problem is the .BAK filename changes every night.Any ideas on how to programatically get the filename into this code?USE MasterGOSET NOCOUNT ON-- 1 - Variable DeclarationDECLARE @DBID intDECLARE @CMD1 varchar(8000)DECLARE @spidNumber intDECLARE @SpidListLoop intDECLARE @SpidListTable table(UIDSpidList int IDENTITY (1,1),SpidNumber int)-- 2 - Populate @SpidListTable with the spid informationINSERT INTO @SpidListTable (SpidNumber)SELECT spidFROM Master.dbo.sysprocesses--WHERE DBID NOT IN (1,2,3,4) -- Master, Tempdb, Model, MSDBWHERE DBID IN (10) -- CCAPP_DEVAND spid > 50AND spid <> @@spidORDER BY spid DESC-- 3b - Determine the highest UIDSpidList to loop through the recordsSELECT @SpidListLoop = MAX(UIDSpidList) FROM @SpidListTable-- 3c - While condition for looping through the spid recordsWHILE @SpidListLoop > 0BEGIN-- 3d - Capture spids locationSELECT @spidNumber = spidnumberFROM @spidListTableWHERE UIDspidList = @SpidListLoop-- 3e - String together the KILL statementSELECT @CMD1 = 'KILL ' + CAST(@spidNumber AS varchar(5))-- 3f - Execute the final string to KILL the spids-- SELECT @CMD1EXEC (@CMD1)-- 3g - Descend through the spid listSELECT @SpidListLoop = @SpidListLoop - 1ENDSET NOCOUNT OFFGOALTER DATABASE CCAPP_DEV SET SINGLE_USER WITH ROLLBACK IMMEDIATE RESTORE DATABASE CCApp_DEVFROM DISK = 'C:\Program Files\Microsoft SQL Server\MSSQL\Backup\ccapp_db_200802070200.BAK'WITH MOVE 'CCApp_Data' TO 'C:\MIS\SQLData\CCApp_DEV.mdf',MOVE 'CCApp_Log' TO 'C:\MIS\SQLData\CCApp_DEV_log.ldf' GOALTER DATABASE CCAPP_DEV SET NULTI_USER GO
Thanks