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
 General SQL Server Forums
 New to SQL Server Programming
 How to put a resultset of a System SP into a table

Author  Topic 

mageshks
Yak Posting Veteran

59 Posts

Posted - 2006-10-30 : 22:35:02
Hi,
How to put a resultset of a System Stored Procedure into a table?.
For Ex,
I want to put the result of sp_Databases into a table

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-10-30 : 22:36:47
[code]
create table #temp
(
DATABASE_NAME varchar(100),
DATABASE_SIZE int,
REMARKS varchar(100)
)

insert into #temp exec sp_databases

select * from #temp

drop table #temp
[/code]


KH

Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-31 : 09:05:49
Also note that as Tan's example, destination table should have similar structure as that of what sp returns


Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

spirit1
Cybernetic Yak Master

11752 Posts

Posted - 2006-10-31 : 09:53:26
for unknown sproc use this:

-- add 'loopback' linkedserver
if exists (select * from master..sysservers where srvname = 'loopback')
exec sp_dropserver 'loopback'
go
exec sp_addlinkedserver @server = N'loopback',
@srvproduct = N'',
@provider = N'SQLOLEDB',
@datasrc = @@servername
go

select * into #t from openquery(loopback, 'exec sp_databases')
select * from #t
drop table #t
go




Go with the flow & have fun! Else fight the flow
blog thingie: http://weblogs.sqlteam.com/mladenp
Go to Top of Page
   

- Advertisement -