Solved

How to change a filename during a swl on the fly.

Posted on 2007-11-20
2
257 Views
Last Modified: 2010-03-19
Some Background:
My company has production servers and on a daily basis we download a database to our lan so we can run reports from it. The code we use to load the database is as follows:

USE master
RESTORE DATABASE cheshire_Reporting
FROM DISK = 'C:\BAckup\cheshire\cheshire_backup_200711190030.bak'
WITH  REPLACE
, MOVE 'cheshire_Data' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\cheshire_reporting_Data.mdf'
, MOVE 'cheshire_Log' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\cheshire_reporting_Log.ldf'
, MOVE 'sysft_ft_cheshire' TO 'C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\sysft_ft_cheshire_reporting'
GO
I created a sql jog with this code and it works with no problems.

Problem:
My production server is set up to save the .bak file as the filename_Backup_Date.bak.
For ex. - cheshire_backup_200711190030.bak
This date changes everyday

Question - Is there a way to create a sql server job that I can set up to run daily that will take this name
change into consideration??

thanks
John

0
Comment
Question by:hexvader
2 Comments
 
LVL 25

Accepted Solution

by:
imitchie earned 250 total points
ID: 20324142
DECLARE @place varchar(max)
set @place = 'C:\BAckup\cheshire\cheshire_backup_' + replace(replace(replace(convert(varchar(16), getdate(), 20),'-', ''),' ',''),':','') + '.bak'
RESTORE DATABASE cheshire_Reporting
FROM DISK = @place
0
 

Author Comment

by:hexvader
ID: 20327807
We had to manipulate the code slighly to deal with the date actually being 1 day behind the current date but it worked like a charm.
Thanks and happy Thanks!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
Everyone has problem when going to load data into Data warehouse (EDW). They all need to confirm that data quality is good but they don't no how to proceed. Microsoft has provided new task within SSIS 2008 called "Data Profiler Task". It solve th…
Via a live example, show how to shrink a transaction log file down to a reasonable size.
Using examples as well as descriptions, and references to Books Online, show the documentation available for datatypes, explain the available data types and show how data can be passed into and out of variables.

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now