title: Row count function always returns NULL
body: <p>I have created an SQL function that implements an faster alternative  to the <code>COUNT(*)</code> operation:</p>
  
  <pre><code>create function fast_row_count (@table_name varchar)
  returns bigint 
  as 
  begin
  declare @row_count int; 
  set @row_count = 
  (select sum(row_count) from sys.dm_db_partition_stats with (nolock) where object_id = object_id(@table_name));
  return @row_count
  end
  go
  </code></pre>
  
  <p>When executing, it always returns a NULL value.</p>
  
  <pre><code>select dbo.fast_row_count('tbl_calls')
  </code></pre>
  
  <p>However, when executing  as a separate batch with a hardcoded value , it works correctly:</p>
  
  <pre><code>    declare @row_count int;
      set @row_count = 
      (select sum(row_count) from sys.dm_db_partition_stats with (nolock) where object_id = object_id('tbl_calls'));
      print  @row_count
  </code></pre>