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"
khalAsked:
Who is Participating?

Improve company productivity with a Business Account.Sign Up

x
 
clarkdConnect With a Mentor Commented:
Are the stored procedures (SP) in the same database.  If so then you simply add the line:  exec       <sp_name>
If not then you need to give the full reference to the SP.
If this doesn't help, cut and paste your sp into a comment box.

0
 
khalAuthor Commented:
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?
0
 
zimmyCommented:
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?
0
Build your data science skills into a career

Are you ready to take your data science career to the next step, or break into data science? With Springboard’s Data Science Career Track, you’ll master data science topics, have personalized career guidance, weekly calls with a data science expert, and a job guarantee.

 
khalAuthor Commented:
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)
0
 
zimmyCommented:
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.
0
 
mitekCommented:
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



0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.