COUNT_BIG (TSQL Function)

Returns the count of the column values.

It is exactly the same as COUNT, except that it always returns bigint.

Syntax

COUNT_BIG ( expression )

COUNT_BIG ( * )

Arguments

expression
is an expression of any type.

Return Types

Returns bigint.

Remarks

NULL values in the expression are ignored.

COUNT_BIG(*) counts all expressions, including NULL values.

Examples

DECLARE @t TABLE (
    id         INT NOT NULL PRIMARY KEY,
    name       VARCHAR(30),
    birthdate  DATE,
    children   TINYINT
);

INSERT INTO @t VALUES (10, 'John',  '19700301', 1),
                      (20, 'Fred',  '20021123', NULL),
                      (40, 'Alex',  '19950712', 2),
                      (50, 'Maria', '19700322', 0),
                      (30, 'Alice', '19950101', NULL),
                      (15,  NULL,   '19950101', 5);

SELECT YEAR(birthdate), SUM(children), COUNT_BIG(*), COUNT_BIG(children)
FROM @t
GROUP BY YEAR(birthdate)
ORDER BY YEAR(birthdate);

The result is:

$g$0       |$sum$1              |$count$2   |$count$3   |
-----------+--------------------+-----------+-----------+
       1970|                   1|          2|          2|
       1995|                   7|          3|          2|
       2002|              <NULL>|          1|          0|

(3 row(s) affected)
RSQL, a simple alternative to Microsoft SQL Server