How to use sp_executesql and WITH RECOMPILE . plz

  • I read these 2 tips for store procedure . some1 tell me with example how to use them.

    1-Use the sp_executesql stored procedure instead of the EXECUTE statement

    Is this used like sp_executesql Store procedure name(But not working)

    11. Add the WITH RECOMPILE option to the CREATE PROCEDURE statement if you know that your query will vary each time it is run from the stored procedure.

    How to use it . What are the benifits?

  • <<Is this used like sp_executesql Store procedure name(But not working)>>

    Please dump the sample code which you are trying to run.

    Somebody will be able to help resolve the problem.

    Regarding RECOMPILE

    --------------------

    You need to use WITH RECOMPILE option carefully. When this option is used the stored procedure is recompiled before execution (each time), and hence there will be an additional overhead.

    Some times the stored procedure refers to temporary tables or uses tables whose contents change drastically. So in these cases using the RECOMPILE option makes sure that sql server uses the right plan relavent to current data/temp table.

    For synatax please refer to BOL.

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

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