November 16, 2009 at 8:40 am
This is what i´ve got so far...
declare @strdatabase nvarchar(50)
declare @strfolder nvarchar(500)
set @strdatabase = N'labmanager'
set @strfolder = N'E:\'
declare @tToday datetime
set @tToday = getdate()
declare @strbackupname nvarchar (100)
SET @strbackupname = @strdatabase + N''
+ str(datepart(year,@tToday),4,0)
+ replace(str(datepart(month,@tToday),2,0),N'',N'0')
+ replace(str(datepart(day,@tToday),2,0),N'',N'0')
+ replace(str(datepart(hour,@tToday),2,0,),N'',N'0')
+ replace(str(datepart(minute, @tToday),2,0),N'',N'0')
declare @strbackupfile nvarchar(600)
set @strbackupfile = @strfolder + N'\' +strbackupname +N'.bak'
backup database @strdatabase
to disk = @strbackupfile;
with noformat,init,skip,name = @strbackupname
I´m having sintaxis error...thanks...
November 16, 2009 at 8:55 am
+ replace(str(datepart(hour,@tToday),2,0,),N'',N'0')
There is a comma after 0 and before parenthesis. By the way shouldnt u be writing dynamic sql at the end?
---------------------------------------------------------------------------------
November 17, 2009 at 9:16 am
Here is your modified code:
declare @strdatabase nvarchar(50)
declare @strfolder nvarchar(500)
set @strdatabase = N'labmanager'
set @strfolder = N'E:\'
declare @tToday datetime
set @tToday = getdate()
declare @strbackupname nvarchar (100)
SET @strbackupname = @strdatabase + N''
+ str(datepart(year,@tToday),4,0)
+ replace(str(datepart(month,@tToday),2,0),N'',N'0')
+ replace(str(datepart(day,@tToday),2,0),N'',N'0') -- There was comma after 2,0
+ replace(str(datepart(hour,@tToday),2,0),N'',N'0')
+ replace(str(datepart(minute, @tToday),2,0),N'',N'0')
declare @strbackupfile nvarchar(600)
set @strbackupfile = @strfolder + N'\' +strbackupname +N'.bak'
backup database @strdatabase
to disk = @strbackupfile --; No Semi colon is required here in SQL Server2005
with noformat
,init
,skip
,name = @strbackupname
November 17, 2009 at 9:19 am
thanks guys!!! it has been working since yesterday...
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply