2

sp_spaceused, when executed without any parameters, produces 2 result sets

database_name, database_size, unallocated_size  
reserved, data, index_space, unused

Usually when you execute some SP, you can insert output into temp table like below example:

insert #temp (column1, column2, column3)
exec sp_someprocedure

but in case of sp_spaceused (without any parameters) - can not insert output, since it produces 2 result sets. I know 2016 has nice parameter @oneresultset = 1, but is there any way you can insert 2 or more output result sets into #temp in SQL 2014 or lower ?

Is there any tricks ?

2 Answers 2

1

A trick to inserting two result sets into one table? No. I do not believe that is possible.

However, what I've done in the past, as I'm sure you have experimented with, is modify the code inside the stored procedure and create a custom version to deploy and call instead.

-1
CREATE TABLE #DatabaseSizes_4
(
    database_name NVARCHAR(128),
    database_size VARCHAR(18),
    unallocated_space VARCHAR(18),
    reserved VARCHAR(18),
    data VARCHAR(18),
    index_size VARCHAR(18),
    unused VARCHAR(18)
);

INSERT INTO #DatabaseSizes_4
EXEC sp_spaceused @oneresultset = 1

select * from #DatabaseSizes_4

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.