views:

19

answers:

1

How do I capture the output from the following SQL statement so I can query the resultset?:

RESTORE FILELISTONLY FROM 
    DISK = N''D:\Restores\MyBackup.BAK'' WITH NOUNLOAD,  
    FILE = 1

Do I need to create a temporary table and then do something like?:

INSERT #tmp EXEC ('RESTORE FILELISTONLY FROM  
    DISK = N''D:\Restores\KevsProfilerTraces.BAK'' WITH  NOUNLOAD,  FILE = 1')

I basically want to query the LogicalName and PhysicalName columns for some management tasks.

Or is there an easier way?

+1  A: 

If your logic is in T-SQL then the only way is using INSERT ... EXEC ... as you already have in your post. It can be a #temp table or it can be a table @variable.

Other alternatives are to move the logic out of T-SQL into CLR procedures or into SSIS workflows.

Remus Rusanu