Home Forums SQL Server 2008 T-SQL (SS2K8) Prevent Stored Procedure using bad execution plan RE: Prevent Stored Procedure using bad execution plan

  • If it is parameter sniffing causing the problem then you can just alter the stored procedure to copy the parameters passed in into ones created within the SP.

    Example:

    GO

    CREATE PROCEDURE mySPWithParameterSniffing

    (

    @Param1 varchar(10),

    @Param2 int

    )

    AS

    BEGIN

    SELECT *

    FROM myTable

    WHERE Col1 = @Param1

    AND Col2 = @Param2

    END

    GO

    GO

    CREATE PROCEDURE mySPWithNoParameterSniffing

    (

    @Param1 varchar(10)

    @Param2 int

    )

    AS

    BEGIN

    DECLARE @Param1x varchar(10),

    DECLARE @Param2x int

    SELECT @Param1x=@Param1, @Param2x=@Param2

    SELECT *

    FROM myTable

    WHERE Col1 = @Param1x

    AND Col2 = @Param2x

    END

    GO