Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase 12»»

Store Procedure Expand / Collapse
Author
Message
Posted Friday, February 6, 2009 4:58 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

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
Posted Friday, February 6, 2009 6:10 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, July 19, 2013 2:52 AM
Points: 9, Visits: 80
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
Posted Friday, February 6, 2009 6:15 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 1:09 PM
Points: 23,253, Visits: 31,946
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
Posted Friday, February 6, 2009 6:25 AM


SSCoach

SSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoachSSCoach

Group: General Forum Members
Last Login: Today @ 4:56 AM
Points: 15,646, Visits: 28,028
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
Posted Friday, February 6, 2009 6:33 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 1:09 PM
Points: 23,253, Visits: 31,946
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
Posted Friday, February 6, 2009 8:23 AM


Ten Centuries

Ten CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen CenturiesTen Centuries

Group: General Forum Members
Last Login: Tuesday, February 18, 2014 7:14 AM
Points: 1,344, Visits: 1,983
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
Posted Saturday, February 7, 2009 3:59 AM
SSC Eights!

SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!SSC Eights!

Group: General Forum Members
Last Login: Wednesday, April 30, 2014 10:27 AM
Points: 957, Visits: 160
Hi
I agree with the @@Nestlevel


Aram Koukia: http://www.koukia.ca
Post #652164
Posted Saturday, February 7, 2009 9:17 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 1:09 PM
Points: 23,253, Visits: 31,946
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
Posted Monday, February 9, 2009 6:36 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

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
Posted Monday, February 9, 2009 6:49 AM


SSC-Insane

SSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-InsaneSSC-Insane

Group: General Forum Members
Last Login: Today @ 1:09 PM
Points: 23,253, Visits: 31,946
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 »

Add to briefcase 12»»

Permissions Expand / Collapse