Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 sp_spaceused

Author  Topic 

george
Starting Member

4 Posts

Posted - 2007-11-12 : 17:27:42
I want to run the stored procedure sp_spaceused and get the first result set into a temp table. I want to do this in tsql and not in .Net code. Was not sure how to go about doing that.

Thanks

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-11-12 : 17:30:19
You can with the first resultset, not the second.

create table #temp (col1, col2, col2, ...)

insert #temp
exec sp_spaceused


E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2007-11-12 : 17:36:32
This is not possible (unless you want it at the object level instead of the database level) since it is producing more than one result set. So you'll need to extract what you need from the code of sp_spaceused.

I just use .NET CLR to do this though. Why can't you do it that way?

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/
Go to Top of Page

Michael Valentine Jones
Yak DBA Kernel (pronounced Colonel)

7020 Posts

Posted - 2007-11-12 : 17:39:25
I'm not sure what you are trying to do, but the script on the link below puts the output of sp_spaceused into temp tables, and then runs queries from it.

Script to analyze table space usage
http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=61762

CODO ERGO SUM
Go to Top of Page

george
Starting Member

4 Posts

Posted - 2007-11-13 : 13:39:38
Thanks (Michael Valentine Jones) that solved my problem.

I was also really just interested in knowing if it was possible to get the different record sets from tsql like I do in .Net. I guess that is not possible.
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2007-11-13 : 13:41:09
If you want to retreive this information in .Net, try the WMI provider for SQL Server 2005.



E 12°55'05.25"
N 56°04'39.16"
Go to Top of Page
   

- Advertisement -