I am trying to script the process RESTORE FILELISTONLY using an Exec()
statement. I cant seem to get it to work with a variable. Here is
what I have.
Declare @Sql varchar(100)
Declare @File varchar(100)
Select @File = 'C:\atest\RO_Backup.bak'
SELECT @Sql = ''''+ 'RESTORE FILELISTONLY FROM DISK=''' + '''' + @File
+ '''' + '''' + ''''
Exec (@Sql)
The above gives me an error: Msg 102, Level 15, State 1, Line 1
Incorrect syntax near 'RESTORE FILELISTONLY FROM DISK='C:\atest
\RO_Backup.bak''.
However, the following DOES work:
Exec ('RESTORE FILELISTONLY FROM DISK=''c:\atest\RO_Backup.bak''')
How can i get it to work with a variable in the Exec statement? If i
do a print statement for the @Sql variable, all the 'quotes' are in
the rite place and quantity as in the above Exec statement, but it
wont work.
Thanks!!
Greg