Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Run stored procedure within another stored procedure

Status
Not open for further replies.

schum1

Technical User
Mar 20, 2001
6
ZA
Hello,

Our company has an Intranet that displays contact details for contact persons and organisations on separate pages for each. The asp pages get their information from SQL stored procedures (GetContactPersonAddresses for contact persons, and GetContactOrgAddresses for contact organisations).

Contact persons are linked to an organisation, and I want to display the organisation's address if the person does not have one. Can this be done by running GetContactOrgAddresses within the ContactPersonAddresses?

I am a novice (a contractor designed the ASP pages and stored procedures) Any ideas are very welcome.

Thank you
Marietjie
 
yes you can call a proc from within a proc.
You can use the IF EXISTS statement to check if the first query returns a resultset and then exec the other stored proc inside your original one.
 
Yes but you would probably be better including the processing in the SP.

You can call another SP and get the result by either

-- output parameter
declare @result ...
exec mysp @p1, ..., @result out

-- resultset
create table #result (...)
insert #result
exec mysp @p1, ...


======================================
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.
 
Thank you, both of you, for replying so quickly. I'll try out your suggestions
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top