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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Is EXEC necessary for stored procs?

Status
Not open for further replies.

maccaroo

Programmer
Jan 28, 2005
11
0
0
GB
Hi

I'm a little confused as to the need to use EXEC when calling a stored procedure. Sometimes I get errors and sometimes I get away with it. Is there a way to tell when it is necessary?

For example, I have a stored proc which runs 3 other stored procs. The 1st and 3rd one only work with EXEC in front, but the 2nd one runs fine without. FYI, the 2nd and 3rd proc do practically the same thing, but to different tables:

--Check for new types
EXEC usp_update_types_table

--Move through contact audits one by one
usp_resolve_single_user_audit

--Move through prop audits one by one
EXEC usp_resolve_single_org_audit
 
The only time you can leave the EXEC out is if the SP call is the first line of a batch. Personally, I am in the habit of always using EXEC - that way you don't need to worry about errors and it makes it more obvious, when looking at the script, what you're doing.

This is fine (no EXEC):

Code:
apMyProc

This will fail if you remove the EXEC:

Code:
SELECT c1 FROM t1

EXEC apMyProc

--James
 
Thanks

I'll stick on the EXEC's from now on.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top