hi all,
This is easier if you use DTS/VBscript but I dont have that option this time.
I'm trying to automate a database restore. My problem at this point is just getting a list of the .bak files that exist in the specified path.
I'm using the DIR command, but getting a syntax error. (see last sentence)
Thanks for any tips. John
Declare @FilePath varchar(100)
Declare @FileName varchar(100)
DECLARE @SQLstmt varchar(2000), @RestoreDB varchar(200), @Cmd varchar(2000), @Return int
Set @FilePath = 'C:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\'
Set @FileName = 'webapp%.bak'
SET @Cmd = 'DIR ' + '''' + @FilePath + ''''
CREATE TABLE #BACKUPS (DBname varchar(100))
INSERT #BACKUPS EXECUTE @Return = master..xp_cmdshell @Cmd
.... when I run the above code in Q-A, it gives this error:
"The filename, directory name, or volume label syntax is incorrect"
This is easier if you use DTS/VBscript but I dont have that option this time.
I'm trying to automate a database restore. My problem at this point is just getting a list of the .bak files that exist in the specified path.
I'm using the DIR command, but getting a syntax error. (see last sentence)
Thanks for any tips. John
Declare @FilePath varchar(100)
Declare @FileName varchar(100)
DECLARE @SQLstmt varchar(2000), @RestoreDB varchar(200), @Cmd varchar(2000), @Return int
Set @FilePath = 'C:\Program Files\Microsoft SQL Server\MSSQL\BACKUP\'
Set @FileName = 'webapp%.bak'
SET @Cmd = 'DIR ' + '''' + @FilePath + ''''
CREATE TABLE #BACKUPS (DBname varchar(100))
INSERT #BACKUPS EXECUTE @Return = master..xp_cmdshell @Cmd
.... when I run the above code in Q-A, it gives this error:
"The filename, directory name, or volume label syntax is incorrect"