March 26, 2012 at 6:02 am
Good Morning.
I am writing a backup script and getting the following error message:
Msg 137, Level 15, State 2, Line 7
Must declare the scalar variable "@ arquivo_DIF."
It is a script to restore FULL and Differential Backups.
If you run the backups work separately, but the script is giving this error.
code position below:
[/code]Declare @pasta char(3),
@arquivo_FULL varchar(255),
@arquivo_DIF varchar(255),
@caminho varchar(255)
set @pasta = case datepart( dw, getdate() )
when '1' then 'Dom' when '2' then 'Seg' when '3' then 'Ter' when '4' then 'Qua'
when '5' then 'Qui' when '6' then 'Sex' when '7' then 'Sab'
end
set @caminho = 'T:\Backup\' + @pasta + '\'
set @arquivo_FULL = @caminho + 'bkpFULL_'+ 'db1' + '_' + @pasta + '_00_00.BAK'
set @arquivo_DIF = @caminho + 'bkpDIF_' + 'db1' + '_' + @pasta + '_06_01.BAK'
use master
RESTORE DATABASE [db1_teste]
FROM DISK = @arquivo_FULL
WITH STATS = 5, FILE = 1, MOVE N'DB1_Novo_Data' TO N'D:\Dados\DB1_Teste.MDF', MOVE N'DB1_Novo_Log' TO N'L:\Log\DB1_Teste.LDF'
, NORECOVERY, NOUNLOAD, REPLACE
GO
/* - Restaurando o Diferencial */
use master
RESTORE DATABASE [DB1_Teste]
FROM DISK = @arquivo_DIF
WITH STATS = 3, FILE = 1, MOVE N'DB1_Novo_Data' TO N'D:\Dados\DB1_Teste.MDF',
MOVE N'DB1_Novo_Log' TO N'L:\Log\DB1_Teste.LDF',NORECOVERY
GO
RESTORE DATABASE DB1_Teste WITH RECOVERY
GO
[/code]
Thanks for any help...
March 26, 2012 at 6:09 am
remove the GO statements.
a GO statement ends the previous batch,and destroys the declared variables as well.
if you remove the GO statmeents, the variables will still be there, and you are good to go!
Lowell
March 26, 2012 at 7:42 am
Thanks, was just doing what you said worked perfectly!
Thank you for your attention.
Solved.
Viewing 3 posts - 1 through 2 (of 2 total)
You must be logged in to reply to this topic. Login to reply