且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

为什么这个查询在存储过程中返回不同的结果?

更新时间:2023-12-03 19:51:52

在将 ANSI_NULLS 设置为 ON 后尝试更改会话中的存储过程.

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

SET ANSI_NULLS ON
GO

alter procedure procedureName 
...

来自文档:

对于存储过程,SQL Server 使用SET ANSI_NULLS 设置值来自的初始创建时间存储过程.每当存储程序随后被执行,SET ANSI_NULLS 的设置是恢复到原来的使用价值并生效.在内部调用时一个存储过程,SET的设置ANSI_NULLS 未更改.

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.