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 2000 Forums
 SQL Server Development (2000)
 sp results >> table

Author  Topic 

Tim
Starting Member

392 Posts

Posted - 2003-04-21 : 23:25:36

exec msdb.dbo.sp_enum_dtspackagelog 'dts_package_name'
exec msdb.dbo.sp_enum_dtssteplog

How do you get the results of these stored procedures into a temporary table (efficiently) ?



robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-04-21 : 23:38:23
Usually whenever I want to INSERT rows into a table, I reach for my handy INSERT statement, with the even handier INSERT INTO #table EXECUTE myStoredProcedure syntax. Pretty efficient if you ask me, sure beats typing it in by hand.



Go to Top of Page

Tim
Starting Member

392 Posts

Posted - 2003-04-22 : 00:33:08
Thanks Rob,

I looked for ages in BOL but didn't think to look at INSERT [:|]

It's a pain that INSERT INTO #table EXECUTE myStoredProcedure requires #table to already exist.



Here's what I'm up to:

I need to report some info logged by DTS. I don't have access to the table msdb.dbo.sysdtssteplog, but I do have access to the stored procedure msdb.dbo.sp_enum_dtssteplog.

So I thought of doing this:

insert into #dtsStepLog exec msdb.dbo.sp_enum_dtssteplog

then dumping the sp_enum_dtspackagelog stored procedure log as well (for the package(s) I am interested in). Then I'd be able to join up the records and select what I want.

Since I need the temp tables to exist already I will have to create them, but then I am screwed if the sysdts% tables change in a service pack or something. I guess I am screwed anyway for using undocumented sp's.

Do you know of a better way of acheiving what I want to do by any chance?



Go to Top of Page

Tim
Starting Member

392 Posts

Posted - 2003-04-22 : 01:09:31
hmmm

heres the code of the stored procedure:


CREATE PROCEDURE sp_enum_dtssteplog
@lineagefull UNIQUEIDENTIFIER = NULL, -- all steps in this package execution
@stepexecutionid BIGINT = NULL
AS
SET NOCOUNT ON

--// This is used for realtime viewing of package logs, so don't error if no entries
--// found, simply return an empty result set.
--// This query must be restricted within a single package execution (lineage); it may
--// be further restricted by stepexecutionid to a single step within that package execution.
SELECT
stepexecutionid,
lineagefull,
stepname,
stepexecstatus,
stepexecresult,
starttime,
endtime,
elapsedtime,
errorcode,
errordescription,
progresscount
FROM sysdtssteplog
WHERE (@lineagefull IS NULL OR lineagefull = @lineagefull)
AND (@stepexecutionid IS NULL OR stepexecutionid = @stepexecutionid)
ORDER BY stepexecutionid

RETURN 0 -- SUCCESS

GO



The following error is produced by running the code below:

 
Server: Msg 213, Level 16, State 7, Procedure sp_enum_dtssteplog, Line 11
Insert Error: Column name or number of supplied values does not match table definition.

--------
DROP TABLE #dtsStepLog

SELECT
stepexecutionid,
lineagefull,
stepname,
stepexecstatus,
stepexecresult,
starttime,
endtime,
elapsedtime,
errorcode,
errordescription,
progresscount
INTO #dtsStepLog
FROM msdb.dbo.sysdtssteplog

TRUNCATE TABLE #dtsStepLog

INSERT #dtsStepLog EXEC msdb.dbo.sp_enum_dtssteplog null, null



clues anyone? (did all the above with sa login)

Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2003-04-22 : 01:23:12
stepexecutionid is an identity - you need to make it a non-identity value.

You can do
SELECT
stepexecutionid = convert(bigint, 0),
lineagefull,
stepname,
stepexecstatus,
stepexecresult,
starttime,
endtime,
elapsedtime,
errorcode,
errordescription,
progresscount
INTO #dtsStepLog
FROM msdb.dbo.sysdtssteplog
where 1=0

and remove the truncate.

You're not relying on the structure of the system tables - you're relying on the output of the sp.

Must be something strange about your system if you can't access the table and can't get the result of the package when you run it.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2003-04-22 : 01:25:31
And you can create a table from an SP by

select * into #a from openquery(...

But I wouldn't recommend it.

==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Tim
Starting Member

392 Posts

Posted - 2003-04-22 : 01:46:39
thanks nigel

... what do you mean bythis bit:

Must be something strange about your system if you can't access the table and can't get the result of the package when you run it.


??

Go to Top of Page

nr
SQLTeam MVY

12543 Posts

Posted - 2003-04-22 : 01:59:36
Just odd that you can run the SP but not access the table.

I guess you are trying to get result info about the packages you are running.
I would normally put this in whatever I use to run the packages (usually VB but possibly t-sql) rather than relying on logging.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -