Link to home
Start Free TrialLog in
Avatar of khal
khal

asked on

make a stored procedure reads from another stored procedure?

how can I make a stored procedure read from another stored procedure( select     from [name of stored procedure]). Every time I try to do that I get an error "invalid object name (name of the stored procedure I'm trying to read from). for more information about the question history you can check the question under the title "copy SQL query from Access to SQL"
ASKER CERTIFIED SOLUTION
Avatar of clarkd
clarkd

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of khal
khal

ASKER

its not working, I added exec <stored proc name> to the calling stored procedure, but still not working. Whats the comment box you talked about, could explain more please?
Your question is unclear.

Do you want one stored procedure to read the CODE from another stored procedure? (Why????)

Or do you want one stored procedure to read the data results of another stored procedure?
Avatar of khal

ASKER

exactly one stored proc(First) to read the results of another stored proc(second). The results are in a form of a table (i.e. the second stored proc has a select statement that produces a lot of data records and I want the First SP to read these records and do some stuff on them)
Have FIRST create a temporary table (name must start with a #) Call SECOND, as clarkd suggests, but have it insert its records into the temp table.
Something like that. I just answered a similar question.

DECLARE @01 varchar(255)

CREATE TABLE #temp(sid int,fname varchar(10))

INSERT INTO #temp EXEC stored_proc @param1,@param2

SELECT * FROM #temp

DROP TABLE #temp

and the first statement in stored_proc must be something like SELECT filed1,field2, to match the structure of temp table