Exit from a store proc if table or another storeproc not exist

  • Hi guys,

    how can i verify if a table or store proc exist and if not exist exit the procedure.

    I tried with:

    if object_id(tablename) is  null

    begin

    return  (-1)

    end

    but SQL give an error :

    A RETURN statement with a return value cannot be used in this context,

    theb same with:

    IF EXISTS(select....sysobject...type = 'U')

    .....

     

    Any idea how to exit from a store proc if a table does not exit.

    I thought :

    select....sysobject...type = 'U'

    if @@rowcount = 0

    RETURN

    Another way ...?

     

    Any help will be very appreciated.

  • Declare @ObjectExists bit

    IF object_id(tablename) is  null

    SET @ObjectExists = 0

    ELSE

    SET @ObjectExists = 1

    .....

    _____________
    Code for TallyGenerator

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

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