Log in
::
Register
::
Not logged in
Home
Tags
Articles
Editorials
Stairways
Forums
Scripts
Videos
Blogs
QotD
Books
Ask SSC
SQL Jobs
Training
Authors
About us
Contact us
Newsletters
Write for us
Recent Posts
Recent Posts
Popular Topics
Popular Topics
Home
Search
Members
Calendar
Who's On
Home
»
SQL Server 2005
»
Development
»
Store Procedure
12 posts, Page 1 of 2
1
2
»»
Store Procedure
Rate Topic
Display Mode
Topic Options
Author
Message
Dbs-887309
Dbs-887309
Posted Friday, February 06, 2009 4:58 AM
Grasshopper
Group: General Forum Members
Last Login: Thursday, February 12, 2009 10:38 PM
Points: 12,
Visits: 44
Hi
I have two procedures
a) Procedure A
b) Procedure B
By design, Procedure B calls Procedure A internally. However, Two procedures can be executed independantly .
I want to findout that if procedure A is called
- Is it called from Procedure B or
- is it called independantly ie not from any other procedure
Your reply will help me a lot
Thanks
Venkat
Post #651516
hkphooey
hkphooey
Posted Friday, February 06, 2009 6:10 AM
Forum Newbie
Group: General Forum Members
Last Login: Monday, May 20, 2013 8:40 AM
Points: 9,
Visits: 73
The first answer that springs to mind is to add a parameter to stored proc A:
CREATE sprocA @calledby char(1)=NULL AS...
Then when you call it from sprocB, call it by using " EXEC sprocA 'B' ", while when calling it independently, use " EXEC sprocA ". You can then interrogate parameter @calledby to determine whether sprocB called it.
Hope this helps.
Post #651544
Lynn Pettis
Lynn Pettis
Posted Friday, February 06, 2009 6:15 AM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 11:18 AM
Points: 21,633,
Visits: 27,490
Venkat (2/6/2009)
Hi
I have two procedures
a) Procedure A
b) Procedure B
By design, Procedure B calls Procedure A internally. However, Two procedures can be executed independently .
I want to findout that if procedure A is called
- Is it called from Procedure B or
- is it called independently ie not from any other procedure
Your reply will help me a lot
Thanks
Venkat
If Procedure B creates a local temporary table (example #MyHead) prior to calling Procedure A, you can test for the exitance of the temporary table as Procedure A will be able to see and use the local temporary table internally. If called independent of Procedure B, this table would not exist.
The only other way that I can think of would be a optional parameter to Procedure A that would be used when calling Procedure A from within Procedure B and left null when called independent of Procedure B.
Lynn Pettis
For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here
or
when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here
and
here
Managing Transaction Logs
SQL Musings from the Desert
Fountain Valley SQL
(My Mirror Blog)
Post #651549
Grant Fritchey
Grant Fritchey
Posted Friday, February 06, 2009 6:25 AM
SSChampion
Group: General Forum Members
Last Login: Today @ 3:41 AM
Points: 13,383,
Visits: 25,189
I wouldn't recommend doing this on a production system, but you could capture statement completion events from a trace. Then you'll see when the call is made from proc b.
However, does proc B always call proc A? If so, just use a trace to capture the executions of Proc B.
----------------------------------------------------
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood..." Theodore Roosevelt
The Scary DBA
Author of:
SQL Server 2012 Query Performance Tuning
SQL Server 2008 Query Performance Tuning Distilled
and
SQL Server Execution Plans
Product Evangelist for
Red Gate Software
Post #651558
Lynn Pettis
Lynn Pettis
Posted Friday, February 06, 2009 6:33 AM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 11:18 AM
Points: 21,633,
Visits: 27,490
Should have asked this first, why does Procedure A need to know if it was called by Procedure B or independently of Procedure B?
Lynn Pettis
For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here
or
when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here
and
here
Managing Transaction Logs
SQL Musings from the Desert
Fountain Valley SQL
(My Mirror Blog)
Post #651570
Derek Dongray
Derek Dongray
Posted Friday, February 06, 2009 8:23 AM
Ten Centuries
Group: General Forum Members
Last Login: Monday, May 13, 2013 2:04 AM
Points: 1,342,
Visits: 1,946
You could try looking at @@NESTLEVEL is you know definitely that either A is called directly or B calls A. Of course, if a hypothetical procedure C also calls A then the level won't help.
See
http://msdn.microsoft.com/en-us/library/aa933163(SQL.80).aspx
Derek
Post #651722
aram_golbaghi
aram_golbaghi
Posted Saturday, February 07, 2009 3:59 AM
Mr or Mrs. 500
Group: General Forum Members
Last Login: Friday, October 26, 2012 11:59 PM
Points: 579,
Visits: 87
Hi
I agree with the @@Nestlevel
Post #652164
Lynn Pettis
Lynn Pettis
Posted Saturday, February 07, 2009 9:17 AM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 11:18 AM
Points: 21,633,
Visits: 27,490
Okay, Venkat, you have had several replies to your question as well as I asked of you. How about some feedback?
Lynn Pettis
For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here
or
when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here
and
here
Managing Transaction Logs
SQL Musings from the Desert
Fountain Valley SQL
(My Mirror Blog)
Post #652227
Dbs-887309
Dbs-887309
Posted Monday, February 09, 2009 6:36 AM
Grasshopper
Group: General Forum Members
Last Login: Thursday, February 12, 2009 10:38 PM
Points: 12,
Visits: 44
Hi All
Thankyou verymuch for the solutoins.
I tried using @@Nestlevel and it looks good to me
I implemented the same and tested as well.
Thanks a lot
I can now close this issue.
Venkat
Post #652753
Lynn Pettis
Lynn Pettis
Posted Monday, February 09, 2009 6:49 AM
SSC-Insane
Group: General Forum Members
Last Login: Today @ 11:18 AM
Points: 21,633,
Visits: 27,490
You may close the issue, but you failed to answer the question, why you needed procedure A to know if it was called by procedure B or called independently of another stored procedure.
It is only polite to answer a question when asked.
Lynn Pettis
For better assistance in answering your questions, click here
For tips to get better help with Performance Problems, click here
For Running Totals and its variations, click here
or
when working with partitioned tables
For more about Tally Tables, click here
For more about Cross Tabs and Pivots, click here
and
here
Managing Transaction Logs
SQL Musings from the Desert
Fountain Valley SQL
(My Mirror Blog)
Post #652763
« Prev Topic
|
Next Topic »
12 posts, Page 1 of 2
1
2
»»
Permissions
You
cannot
post new topics.
You
cannot
post topic replies.
You
cannot
post new polls.
You
cannot
post replies to polls.
You
cannot
edit your own topics.
You
cannot
delete your own topics.
You
cannot
edit other topics.
You
cannot
delete other topics.
You
cannot
edit your own posts.
You
cannot
edit other posts.
You
cannot
delete your own posts.
You
cannot
delete other posts.
You
cannot
post events.
You
cannot
edit your own events.
You
cannot
edit other events.
You
cannot
delete your own events.
You
cannot
delete other events.
You
cannot
send private messages.
You
cannot
send emails.
You
may
read topics.
You
cannot
rate topics.
You
cannot
vote within polls.
You
cannot
upload attachments.
You
may
download attachments.
You
cannot
post HTML code.
You
cannot
edit HTML code.
You
cannot
post IFCode.
You
cannot
post JavaScript.
You
cannot
post EmotIcons.
You
cannot
post or upload images.
Copyright © 2002-2013 Simple Talk Publishing. All Rights Reserved.
Privacy Policy.
Terms of Use.
Report Abuse.