If you want to count the number that exceeds the maximum value of INT datatype, you can make use of COUNT_BIG function. COUNT_BIG function always returns a bingint datatype value. Consider the following example code which uses both COUNT_BIG and COUNT function
select COUNT_BIG(*) as big_number, COUNT(*) as number into #t select * from #t
Now execute this code to see the datatypes of these columns
select c.name as column_name, t.name as data_type from tempdb..syscolumns as c inner join tempdb..systypes as t on c.xtype=t.xtype where id=OBJECT_ID('tempdb..#t')
The result is
column_name data_type ----------------- ---------- number int big_number bigint
Note that the big_number column has a datatype of bigint and if you have want to count rows with more than 2147483647 rows you can use that function
Tags: t-sql, sql_server, sqlserver, tsql, BRH, #TSQL, #SQLServer, count, count_big,