title: Error in @@ROWCOUNT inside SQL Server 2019 UDF
body: <p>I found the <code>@@ROWCOUNT</code> when it is used inside a <code>User Defined Function</code> in MS SQL Server 2019 it doesn't work properly any more.</p>
  
  <p>I don't know if it's a MS SQL bug or a desired change of behavior.</p>
  
  <p>There is any option to go back to the behavior of 2019 an previous versions? Is it something about the setup of the installation?</p>
  
  <p>Here is the code and results for your own test:</p>
  
  <pre class="lang-sql prettyprint-override"><code>CREATE FUNCTION [dbo].[udfScalar](@test NVARCHAR(255)) RETURNS int
  AS BEGIN
      DECLARE @var AS NVARCHAR(255)
      DECLARE @ROWCOUNT AS INT = NULL
      select top 1 @var = 'test' from FooTable where 1 = 0
      SET @ROWCOUNT = @@ROWCOUNT
      RETURN @ROWCOUNT;
  END
  GO
      DECLARE @var AS NVARCHAR(255)
      DECLARE @ROWCOUNT AS INT = NULL
      select top 1 @var = 'test' from FooTable where 1 = 0
      SET @ROWCOUNT = @@ROWCOUNT
  
  select @ROWCOUNT '@@ROWCOUNT in T-SQL', [dbo].[udfScalar]('test') '@@ROWCOUNT in UDF', @@VERSION 'MS SQL VERSION'
  drop FUNCTION [dbo].[udfScalar]
  </code></pre>
  
  <p>Result in MS SQL Server 2019 (wrong):</p>
  
  <pre><code>@@ROWCOUNT in T-SQL: 0
  @@ROWCOUNT in UDF:   1
  MS SQL VERSION: Microsoft SQL Server 2019 (RTM) - 15.0.2000.5 (X64) 
      Sep 24 2019 13:48:23 
      Copyright (C) 2019 Microsoft Corporation
      Standard Edition (64-bit) on Windows Server 2019 Standard 10.0 &lt;X64&gt; (Build 17763: ) (Hypervisor)
  </code></pre>
  
  <p>Note that <code>UDF</code> returns <code>1</code> when the the result should be <code>0</code> because of the <code>where 1 = 0</code>.</p>
  
  <p>Result in MS SQL Server 2016 and previous versions (correct):</p>
  
  <pre><code>@@ROWCOUNT in T-SQL: 0
  @@ROWCOUNT in UDF:   0
  MS SQL VERSION: Microsoft SQL Server 2016 (SP2-GDR) (KB4505220) - 13.0.5101.9 (X64) 
      Jun 15 2019 23:15:58 
      Copyright (c) Microsoft Corporation
      Standard Edition (64-bit) on Windows Server 2016 Standard 10.0 &lt;X64&gt; (Build 14393: ) (Hypervisor)
  </code></pre>
  
  <p>Right now I don't have access to SQL Server 2017 but I believe it was correct.</p>