Why does this query return different results when in a stored procedure?

后端 未结 2 1404
北恋
北恋 2021-01-05 15:51

Synopsis

I\'ve got a query with a WHERE clause that contains a condition that checks a NULLable column against a parameter that may be NULL, like so:

2条回答
  •  北海茫月
    2021-01-05 16:31

    Try altering the stored procedure in a session after setting ANSI_NULLS to ON.

    SET ANSI_NULLS ON
    GO
    
    alter procedure procedureName 
    ...
    

    From the docs:

    For stored procedures, SQL Server uses the SET ANSI_NULLS setting value from the initial creation time of the stored procedure. Whenever the stored procedure is subsequently executed, the setting of SET ANSI_NULLS is restored to its originally used value and takes effect. When invoked inside a stored procedure, the setting of SET ANSI_NULLS is not changed.

提交回复
热议问题