Tuesday, March 20, 2012

Save system stored procedure results?

Is there a way to save the results of a system stored procedure into a
table? Example - I want to run xp_fixeddrives and send the results to a
temp table. Is this possible?
Rachael
*** Sent via Devdex http://www.devdex.com ***
Don't just participate in USENET...get rewarded for it!Yes, here's some quick code:
CREATE TABLE #FixedDrivesOutput
(
Drive char(1),
MBFree int
)
GO
INSERT INTO #FixedDrivesOutput (Drive, MBFree)
EXEC master.dbo.xp_fixeddrives
--
Vyas, MVP (SQL Server)
http://vyaskn.tripod.com/
"Rachael Faber" <rfaber@.alldata.net> wrote in message
news:Onzn0A5YEHA.2816@.TK2MSFTNGP11.phx.gbl...
> Is there a way to save the results of a system stored procedure into a
> table? Example - I want to run xp_fixeddrives and send the results to a
> temp table. Is this possible?
> Rachael
>
> *** Sent via Devdex http://www.devdex.com ***
> Don't just participate in USENET...get rewarded for it!|||Hey -
How are you running the SP, ie.. from Query Analyzer, from isql ?
If from Query Analyzer you can save .CSV file or any other type of file and
then load it into a table.
If from isql, redirect the output to a file and then load it into a table.
HTH
"Rachael Faber" <rfaber@.alldata.net> wrote in message
news:Onzn0A5YEHA.2816@.TK2MSFTNGP11.phx.gbl...
> Is there a way to save the results of a system stored procedure into a
> table? Example - I want to run xp_fixeddrives and send the results to a
> temp table. Is this possible?
> Rachael
>
> *** Sent via Devdex http://www.devdex.com ***
> Don't just participate in USENET...get rewarded for it!|||Rachel
try do to something like this
-- Create a table with the same structure that the procedure returns
Create table tempdb.dbo.sphelpdb( name_1 varchar(255), db_size varchar(255), owner varchar(255), db_id int ,created varchar(255), status varchar(255))
-- Insert into the table the results got using a EXEC and procedure with parameters
Insert tempdb.dbo.sphelpdb(name_1, db_size, owner, db_id, created, status)
EXEC('sp_helpdb')
-- Voila! the table contains, the procedure results.
Select * from tempdb.dbo.sphelpdb
"Rachael Faber" wrote:
> Is there a way to save the results of a system stored procedure into a
> table? Example - I want to run xp_fixeddrives and send the results to a
> temp table. Is this possible?
> Rachael
>
> *** Sent via Devdex http://www.devdex.com ***
> Don't just participate in USENET...get rewarded for it!
>

No comments:

Post a Comment