Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 String problem? Not sure...

Author  Topic 

nicoart
Starting Member

11 Posts

Posted - 2006-11-13 : 21:04:52
I am creating script to back up database and would like to set the name of BAK file based on date and Time when the script runs... so I modify the script something like this: BACKUP DATABASE [elldrc] TO DISK = N'V:\DatabaseBackup\elldrc\elldrc_db_' + '200611131548.BAK', later I will replace '200611131548.BAK' with result of CAST, DATEPART, etc functions, but I got error message when I put BACKUP DATABASE [elldrc] TO DISK = N'V:\DatabaseBackup\elldrc\elldrc_db_' + '200611131548.BAK'. Could you tell me why is that?

My first thought because this is Microsoft Product so I think it will be processing string the same as the other Microsoft Products (VB, VBA) but looks like it doesn't...

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-11-13 : 21:29:14
declare a varible for the filename and assign the filename to the variable and use it in the TO DISK = ...


declare @filename nvarchar(1000)
select @filename = N'V:\DatabaseBackup\elldrc\elldrc_db_' + N'200611131548.BAK'
BACKUP DATABASE [elldrc] TO DISK = @filename



KH

Go to Top of Page

nicoart
Starting Member

11 Posts

Posted - 2006-11-13 : 21:50:13
Thanks very much khtan... It works nicely... Sorry, I am newbie in both T-SQL and SQL Server.
Go to Top of Page
   

- Advertisement -