Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
561 views
in Technique[技术] by (71.8m points)

sql server - Unexpected @@rowcount behavior inside an UDF in MS SQL 2019

here's my sample code

drop function rowcount_test
go
CREATE FUNCTION dbo.rowcount_test () RETURNS INT AS
BEGIN
    DECLARE @v INT
    SELECT @v = 1
    return @@ROWCOUNT
END
GO
grant exec on dbo.rowcount_test to public
go
SELECT dbo.rowcount_test()

It gives 1 when executed by mssql 2017 (and earlier)

It gives 0 when executed by mssql 2019

It gives 1 when executed by mssql 2019 (Standard edition) with a db put to the 2017 compatibility mode

It's never been a problem before... Is it a kind of setting affecting the code or a kind of bug in MSSQL 2019?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Scalar udf inlining yet again, rather buggy

SELECT dbo.rowcount_test()

OPTION (USE HINT('DISABLE_TSQL_SCALAR_UDF_INLINING'));

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...