Solved

make a stored procedure reads from another stored procedure?

Posted on 1998-07-13
6
199 Views
Last Modified: 2010-03-19
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"
0
Comment
Question by:khal
6 Comments
 

Accepted Solution

by:
clarkd earned 20 total points
ID: 1091734
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
 

Author Comment

by:khal
ID: 1091735
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
 

Expert Comment

by:zimmy
ID: 1091736
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
Zoho SalesIQ

Hassle-free live chat software re-imagined for business growth. 2 users, always free.

 

Author Comment

by:khal
ID: 1091737
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
 

Expert Comment

by:zimmy
ID: 1091738
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
 
LVL 4

Expert Comment

by:mitek
ID: 1091739
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

Featured Post

Control application downtime with dependency maps

Visualize the interdependencies between application components better with Applications Manager's automated application discovery and dependency mapping feature. Resolve performance issues faster by quickly isolating problematic components.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
MS SQL 2014 get SPIDs of users 6 25
SQL Percentage - Bring back full percentage 5 47
sql query 7 34
Sql query 34 17
Let's review the features of new SQL Server 2012 (Denali CTP3). It listed as below: PERCENT_RANK(): PERCENT_RANK() function will returns the percentage value of rank of the values among its group. PERCENT_RANK() function value always in be…
This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

708 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

16 Experts available now in Live!

Get 1:1 Help Now