Вы можете использовать INSERT INTO EXEC
:
CREATE TABLE temp(...);
INSERT INTO temp(LogicalName, PhysicalName, Type, FileGroupName,...)
EXEC('RESTORE FILELISTONLY FROM DISK = ''C:\BackupFile''');
SELECT * FROM temp;
РЕДАКТИРОВАТЬ:
Чтобы быть независимой от версии получение версии :
DECLARE @version NVARCHAR(100) =
CASE
WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion')) like '8%' THEN 'SQL2000'
WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion')) like '9%' THEN 'SQL2005'
WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion')) like '10.0%' THEN 'SQL2008'
WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion')) like '10.5%' THEN 'SQL2008 R2'
WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion')) like '11%' THEN 'SQL2012'
WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion')) like '12%' THEN 'SQL2014'
WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion')) like '13%' THEN 'SQL2016'
WHEN CONVERT(VARCHAR(128), SERVERPROPERTY ('productversion')) like '14%' THEN 'SQL2017'
ELSE 'unknown'
END;
-- pseudocode
IF @version = 'SQL2017'
EXEC('CREATE TABLE temp(col1, col2, col3)');
IF @version = 'SQL2016'
EXEC('CREATE TABLE temp(col1, col2, col3, col4)');
IF @version = 'SQL2014'
EXEC('CREATE TABLE temp(col1, col2, col3, col4, col5)');
-- no column list(blind insert)
EXEC('INSERT INTO temp
EXEC(''RESTORE FILELISTONLY FROM DISK = ''''C:\BackupFile'''' '')');
GO
-- common columns only
SELECT LogicalName, PhysicalName, Type, FileGroupName
FROM temp;