SQL server procedure|Functions

  • HI

    Is it possible to call procedure|function in the same procedure|function itself..

     

  • yes you can

    but it will usually end in someone crying

    the sql server will also protect it from executing endlessley and will stop it at the nesting level set on your server - a default of 32

    you can test it as follows

    create proc test as

    print 'hello'

    exec test

    GO

    you'll get the message

    Cannot add rows to sysdepends for the current stored procedure because it depends on the missing object 'test'. The stored procedure will still be created.

    but the proc is created

    then call the proc using exec TEST - you'll get

    Server: Msg 217, Level 16, State 1, Procedure test, Line 3

    Maximum stored procedure, function, trigger, or view nesting level exceeded (limit 32).

    hello

    hello

    hello

    hello

    hello

    hello

    hello

    MVDBA

  • --- With the below code i got the result what i want.Any how thq for quick reply.

     

    create procedure proc

    @s-2 int

    as

    declare @b-2 int

    set @b-2=@s-1

    if @b-2 <> -1

    begin

    print 'Chandu'

    exec proc @b-2

    end

     

    Executing         :

                Exec proc 5     

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply