I am having a problem getting a script running.
[!]Results[/!]
Msg 102, Level 15, State 1, Line 12
Incorrect syntax near '@dbName'.
Msg 102, Level 15, State 1, Line 21
Incorrect syntax near '@dbName'.
Msg 102, Level 15, State 1, Line 30
Incorrect syntax near '@dbName'.
[/color red]
Thanks
John Fuhrman
Code:
declare @dbName as VarChar(max)
if exists(SELECT * FROM sys.databases WHERE name LIKE 'ErrorLog_%')
IF Not Exists(SELECT * FROM sys.databases WHERE name Like 'ErrorLog_%')
BEGIN
Set @dbName = 'ErrorLog_' + CONVERT(VARCHAR(max), GETDATE(), 102) +
'_' + REPLACE(CONVERT(VARCHAR(12), GETDATE(), 114),':','.')
Print 'Created Database SnapShot: ' + @dbName
Create Database @dbName On
(Name = ErrorLog, FILENAME =
'D:\Microsoft_SQL_Server\MSSQL10_50.MSSQLSERVER\MSSQL\SnapShots\' + @DBname + '.ss')
As SNAPSHOT OF ErrorLog
END
ELSE
BEGIN
Set @dbName = (SELECT * FROM sys.databases WHERE name Like 'ErrorLog_%')
Drop @dbName
Print 'Dropped Database SnapShot: ' + @dbName
Set @dbName = 'ErrorLog_' + CONVERT(VARCHAR(max), GETDATE(), 102) +
'_' + REPLACE(CONVERT(VARCHAR(12), GETDATE(), 114),':','.')
Print 'Created Database SnapShot: ' + @dbName
Create Database @dbName On
(Name = ErrorLog, FILENAME =
'D:\Microsoft_SQL_Server\MSSQL10_50.MSSQLSERVER\MSSQL\SnapShots\' + @DBname + '.ss')
As SNAPSHOT OF ErrorLog
END
[!]Results[/!]
Msg 102, Level 15, State 1, Line 12
Incorrect syntax near '@dbName'.
Msg 102, Level 15, State 1, Line 21
Incorrect syntax near '@dbName'.
Msg 102, Level 15, State 1, Line 30
Incorrect syntax near '@dbName'.
[/color red]
Thanks
John Fuhrman