我们刚刚从 SQL Server 2008 R2 升级到 SQL Server 2019(Compability lvl 150)。
我们有两个不同的存储过程在升级后开始失败,错误消息如下:
Msg 8632, Level 17, State 2, Procedure BuildSelfSaleStats, Line 14 [Batch Start Line 4]
Internal error: An expression services limit has been reached. Please look for potentially complex expressions in your query, and try to simplify them.
真正奇怪的是,这个特殊的存储过程不带任何参数,当我们简单地在 SSMS 中执行 SQL 代码的主体时,它工作正常(!?)。
什么可能导致某些在 SSMS 中执行时运行良好的 SQL 代码在包装在存储过程中时突然开始失败?
我们设法将错误与我们拥有的日期格式化功能隔离开来:
这在 SSMS 中运行时有效:
select dbo.fn_formatdatetime(DATEADD(month, -6, GETDATE()), 'yyyy-mm')
output:
(No column name)
2019-12
但是当在 testproc 中调用时,它会失败:
CREATE PROCEDURE testproc
AS
BEGIN
SET NOCOUNT ON;
select dbo.fn_formatdatetime(DATEADD(month, -6, GETDATE()), 'yyyy-mm')
END
exec testproc
Msg 8632, Level 17, State 2, Procedure testproc, Line 9 [Batch Start Line 11]
Internal error: An expression services limit has been reached. Please look for potentially complex expressions in your query, and try to simplify them.