SQL Server Performance

Add current date in sql

Discussion in 'ALL SQL SERVER QUESTIONS' started by tarlikak, Jan 8, 2013.

  1. tarlikak New Member

    I have this script, I need to add current date next to 'DIW_TEST' database name,
    how can i do that?

    BACKUP
    DATABASE [DIW_TEST] TODISK=N'I:\Backup\DIW_TEST.bak'WITHNOFORMAT,NOINIT, NAME =N'DIW_TEST-Full Database Backup',SKIP,NOREWIND,NOUNLOAD,STATS=
    10

    GO

    can somebody help me for above query
  2. FrankKalis Moderator

    Something like this should work for you:
    Code:
    DECLARE @DBNamePlusDate varchar(50);
    
    SELECT @DBNamePlusDate = 'DIW_TEST-Full Database Backup_' + CONVERT(char(10), GETDATE(), 120)
    
    BACKUP DATABASE [DIW_TEST] TO DISK=N'I:\Backup\DIW_TEST.bak' WITH NOFORMAT,NOINIT, NAME =@DBNamePlusDate,SKIP,NOREWIND,NOUNLOAD,STATS=
    10
    
    GO
    

Share This Page