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?
Data manipulation language (DML) statements set the @@ROWCOUNT value to the number of rows affected by the query and return that value to the client. The DML statements may not send any rows to the client. DECLARE CURSOR and FETCH set the @@ROWCOUNT value to 1.
Usage. SQL Server @@ROWCOUNT is a system variable that is used to return the number of rows that are affected by the last executed statement in the batch.
The ROWCOUNT Set Function causes the server to stop the query processing after the specified number of records is returned. One may limit the number of records returned by all subsequent SELECT statements within the session by using the keyword SET ROWCOUNT.
In the simplest terms, a user-defined function (UDF) in SQL Server is a programming construct that accepts parameters, does work that typically makes use of the accepted parameters, and returns a type of result.
Scalar udf inlining yet again, rather buggy
SELECT dbo.rowcount_test()
OPTION (USE HINT('DISABLE_TSQL_SCALAR_UDF_INLINING'));
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With