title: read output stored procedure that returns multiple recordsets in sql 2005
body: <p>I'm trying to programmatically access the result of executing the system stored procedure sp_spaceused.</p>
  
  <p>if you pass the name of an object as a parameter, the sp returns a recordset which you can read like this</p>
  
  <pre><code>
  
  CREATE TABLE #TempTable 
  (   [Table_Name] varchar(50),
      Row_Count int,
      Table_Size varchar(50),
      Data_Space_Used varchar(50),
      Index_Space_Used varchar(50),
      Unused_Space varchar(50)
  )
  
  
  insert into #TempTable EXEC( 'sp_spaceused "tablexx"' )
  
  select * from #TempTable
  
  Table_Name   Row_Count   Table_Size  Data_Space_Used  Index_Space_Used  Unused_Space
  ------------ ----------- ----------- ---------------- ----------------- ------------
  tablexx      67          64 KB       16 KB            48 KB             0 KB
  
  (1 row(s) affected)
  
  (1 row(s) affected)
  
  </code></pre>
  
  <p>the problem is that this stored procedure, when used with no parameters returns two different recordset, like this:</p>
  
  <pre><code>
  
  sp_spaceused
  
  database_name  database_size  unallocated space
  -------------- -------------- ------------------
  Convenios      11622.75 MB    3.16 MB
  
  reserved      data          index_size  unused
  ------------- ------------- ----------- ---------
  11897696 KB   11784392 KB   103264 KB   10040 KB
  
  </code></pre>
  
  <p>I just want to get the database_size into a variable... So the problem in fact is how to programmatically access the data returned by a stored procedure that returns multiple recordset...</p>
  
  <p>How can I achieve this?</p>