I am using @@rowcount in my functions like this:
ALTER FUNCTION [dbo].[GetUserNameFamily]
(@UsrID INT)
RETURNS NVARCHAR(MAX)
AS
BEGIN
DECLARE @Name NVARCHAR(MAX)
DECLARE @Family NVARCHAR (MAX)
DECLARE @cou INT
SELECT @Name = ut.Fname, @Family = ut.Lname
FROM User_tbl ut
WHERE ut.UserID = @UsrID
IF @@ROWCOUNT = 0
RETURN 'row 0'
IF @Name IS NULL
SET @Name = ''
IF @Family IS NULL
SET @Family = ''
RETURN @Name + ' ' + @Family
END
When I use this function in a query like that:
declare @ID int=3118
select *
from Files_tbl
where RefID = @ID -- query rows affected is 0
select
dbo.GetUserNameFamily(TicketResponse_tbl.CreateByUserID) as CreateByFullName
from
TicketResponse_tbl
where
TicketResponse_tbl.TicketID = @ID
My result is:
After removing where in "select Files_tbl" query and changed this query rows affected from 0 to n.
declare @ID int = 3118
select *
from Files_tbl
-- where RefID = @ID -- query rows affected is not 0
select
dbo.GetUserNameFamily(TicketResponse_tbl.CreateByUserID) as CreateByFullName
from
TicketResponse_tbl
where
TicketResponse_tbl.TicketID = @ID
My function result changes to :
This problem occurred after upgrading the database compatibility level to SQL Server 2019


PRINT @@VERSION?@@ROWCOUNTwas omitted from inlining in CU2; that was released on 2020-02-13. Your instance doesn't even have the GDR updates, so has known security flaws.