Stored Procedure with varchar(max) as parameter

  • Hi,

    I have this stored procedure:

    create proc ExecuteScripts (@SQLstat varchar(max))

    as

    begin

    exec SQLstat

    end

    When i try to create this procedure i receive the following warning from SQL Server:

    Cannot add rows to sys.sql_dependencies for the stored procedure because it depends on the missing table 'SQLstat'. The stored procedure will still be created; however, it cannot be successfully executed until the table exists.

    But SQLstat is a variable that i want to pass, not a table...

    Can someone explain?

    Thank you

  • Assuming that you are passing the script to be executed in @SQLStat parameter, your procedure should be:

    create proc ExecuteScripts (@SQLstat varchar(max))

    as

    begin

    exec ( @SQLstat )

    end

    Also check sp_executesql if you need to use dynamic sql.

    Neepa

  • thank you.

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

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