This technique shows how get count from MSSQL fast, if you have lot of rows.
I is significantly faster than select count(*) …
But in some cases result couldn't be exact.
The code bellow is code for creating stored procedure, which returns row count of table, which name was passed as a procedure parameter
CREATE PROCEDURE [dbo].[table_Count]
@tableName nvarchar(255),
@ID BIGINT OUTPUT
AS
BEGIN
SELECT @ID=rowcnt
FROM sysindexes
WHERE indid IN (1,0)
AND OBJECTPROPERTY(id, 'IsUserTable') = 1
AND OBJECT_NAME(id) = @tableName
END