Differences between sp_executesql and execute

  • Hi All,

     

    Can any one through some light on differences between sp_executesql and Execute methods? How to select which method we need to use and also in performance point of view which one is better and why?

    Thanks in advance..

    Regards,

    Ramesh K

     

  • From BOL

    Transact-SQL supports two methods of building SQL statements at run time in Transact-SQL scripts, stored procedures, and triggers:

    • Use the sp_executesql system stored procedure to execute a Unicode string. sp_executesql supports parameter substitution similar to the RAISERROR statement.
    • Use the EXECUTE statement to execute a character string. The EXECUTE statement does not support parameter substitution in the executed string.

    Gordon Pollokoff

    "Wile E. is my reality, Bugs Bunny is my goal" - Chuck Jones

  • Thanks Gordon,

    Can you give some info on performance related issues with these two diff types?

    -- Ramesh K

  • Helo Ramesh K,

    sp_executesql give you the opportunity to use parameters. When executing similar satements that are different only on values for those parameter, you can have a performance gain due to execution plan re-use.

    Best regards,

    Carl

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

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