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)
 Help analyzing the results of an EXEC

Author  Topic 

ThreePea
Yak Posting Veteran

83 Posts

Posted - 2003-02-24 : 14:45:41
Hey everyone. This is a quirky problem that may not have any good solutions, but I wanted to throw it out in case i missed something.

I have a customer requirement as follows. A particular table exists that holds the name of various stored procedures. My script will pull out and execute one of these stored procedures (using dynamic SQL) based on various criteria. All of these procedures have one thing in common - they all return a loginname. The kicker is, the column name for the loginname is not always the same, and, the number of columns returned by each procedure is different. Here is a crude example which should clarify:


DECLARE @input_parameter INT
SET @input_parameter = 1
----------------------------

CREATE TABLE #sp
(Proc_Key INT IDENTITY
,Proc_Name VARCHAR(50)
)

INSERT #sp VALUES('sp_who')
INSERT #sp VALUES('sp_who2')

DECLARE @command VARCHAR(100)

SELECT @command = Proc_Name
FROM #sp
WHERE Proc_Key = @input_parameter

EXEC(@command)

DROP TABLE #sp

Whether this script is called with an input of "1" or "2" will determine which proc is executed. Both return a login name, but one calls it "loginame" and the other calls it "Login". Plus they both return a different number of cols. If the results of this proc were being sent to an asp page, I would use ADO to figure out how many columns were returned, and their names.

However, I don't have that luxury. I need to keep processing after the EXEC statement, and I need to have a temp table that is populated with the results of the login name column from the EXEC, whatever that may be.

Make sense? Any ideas?

Thanks.

3P


==================================================
Tolerance is the last virtue of an immoral society. -- G.K. Chesterton
   

- Advertisement -