Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

SQL syntax

Posted on 2008-10-01
4
Medium Priority
?
300 Views
Last Modified: 2010-03-20
This is a Script I would like to Run at Month END to create a special Backup with the Month and year in the file name.


USE [700];
GO
BACKUP DATABASE [700]
TO DISK = 'E:\DB\' & DATENAME(month, getdate()-5) & DATENAME(year, getdate()-5) &'.Bak'
   WITH FORMAT,
      MEDIANAME = 'E_SQLServerBackups',
      NAME = DATENAME(month, getdate()-5) &' End of Month';
GO

Open in new window

0
Comment
Question by:kwitcom
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 32

Accepted Solution

by:
Daniel Wilson earned 1000 total points
ID: 22614187
Change your & to + in your string concatenation.  

Otherwise ... I don't see any problem.
0
 
LVL 11

Assisted Solution

by:aaronakin
aaronakin earned 1000 total points
ID: 22614216
Try this...

USE [700];
GO
DECLARE
      @FileName            VARCHAR(500),
      @BackupName            VARCHAR(500)

SELECT @FileName = 'E:\DB\'+ CAST(YEAR(GETDATE()) AS VARCHAR(4)) +'_'+ RIGHT('0'+CAST(MONTH(GETDATE()) AS VARCHAR(2)),2) +'.bak'
SELECT @BackupName = RIGHT('0'+CAST(MONTH(GETDATE()) AS VARCHAR(2)),2) +'/'+ CAST(YEAR(GETDATE()) AS VARCHAR(4)) +' End of Month'

BACKUP DATABASE [700]
TO DISK = @FileName
   WITH FORMAT,
      MEDIANAME = 'E_SQLServerBackups',
      NAME = @BackupName;
GO
0

Featured Post

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

As they say in love and is true in SQL: you can sum some Data some of the time, but you can't always aggregate all Data all the time! Introduction: By the end of this Article it is my intention to bring the meaning and value of the above quote to…
I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
This tutorial will teach you the special effect of super speed similar to the fictional character Wally West aka "The Flash" After Shake : http://www.videocopilot.net/presets/after_shake/ All lightning effects with instructions : http://www.mediaf…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…

688 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