views:

1059

answers:

6

Hi, I have found that SP2 doesn't execute from within SP1 when SP1 is executed.

Below is the structure of SP1:

ALTER PROCEDURE SP1 AS BEGIN

Declare c1 cursor....

open c1 fetch next from c1 ...

while @@fetch_status = 0 Begin

...

Fetch Next from c1 end

close c1

deallocate c1

exec sp2

end
A: 

Have you tried debugging the stored procedure? I'm wondering if it is not even getting to the exec sp2 line.

mattruma
+2  A: 

What happens if you run the Stored Procedure code as a single query? If you put a PRINT statement before and after the exec, do you see both outputs?

  • If you do, then the stored procedure must have been executed. Probably it's not doing what you would like.
  • If you don't see any print output, then there's something wrong in the cycle
  • If you don't see the second output but you see the first, there's something wrong in the second Stored Procedure.
Sklivvz
A: 

I see non of the PRINT statement outputs if they are printed in the 'Output window' in SQL Server 2005 management studio as the 'Output Window'is empty.

test
so there's something wrong before the exec. the problem is in the while cycle.
Sklivvz
A: 

I am not sure if it helps you, but from my experience the most popular reasons are:

  1. sp2 gets some parameter which makes it null value -- i.e. you build its name from the strings and one of them is null.
  2. sp2 has some conditions inside and none of them is true, so sp2 executes no code at all -- i.e. one of the parameters is type varchar, you pass value VALUE, check for it inside, but the real value passed to sp2 is V (because there are no varchar length defined).
  3. sp2 builds query from parameters where one of them is null and the whole query becomes null too.

Do you see any output if you put PRINT before and after call of sp2?

Grzegorz Gierlik
A: 

you could use @@error to see if there was an error when executing the previous statement.

Bogdan Maxim
A: 

Are you running the stored procedure from the command line, or from within an application? If you're executing it from within an application, make sure your connection isn't being closed before sp2 executes.