Results 1 to 2 of 2
  1. #1
    Join Date
    May 2011

    Unanswered: Recurring database snapshot using variable in filename

    Hi all,

    I'm trying to create multiple snapshots (for a school assignment) that recur every 15 minutes. I want to use a variable in the filename to differentiate. I'm getting an error that says "Incorrect syntax near '+'." Here's what I have so far:

    declare @ssnum int

    set @ssnum = getdate()

    create database awss_ + @ssnum
    (name = AdventureWorks_Data,
    filename = 'c:\Snapshots\awss_data_ + @ssnum .ss'
    as snapshot of AdventureWorks;

    Thanks in advance for any help.


  2. #2
    Join Date
    Nov 2004
    Provided Answers: 4
    Just a few things I noticed:
    - assigning a DATE to an INT variable
    declare @ssnum int
    set @ssnum = getdate()

    - adding an INT to a command
    create database awss_ + @ssnum

    - Misplacing surrounding quotes
    filename = 'c:\Snapshots\awss_data_ + @ssnum .ss'

    declare @ssnum VARCHAR(23)
    SELECT @ssnum = CONVERT(VARCHAR(23), GetDate(), 121) -- or any other format that you want
    filename = 'c:\Snapshots\awss_data_' + @ssnum + '.ss'
    At least those parts need fixing. I can't help you with the rest.
    With kind regards . . . . . SQL Server 2000/2005/2012

    Grabel's Law: 2 is not equal to 3 -- not even for very large values of 2.
    Pat Phelan's Law: 2 very definitely CAN equal 3 -- in at least two programming languages

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts