how to find count | SQL Server Performance Forums

SQL Server Performance Forum – Threads Archive

how to find count

dear all i need to find last count value while inserting new record in the table advance thanks
Which "count"? If the table has an identity column, it increases automatically. If you need to use the identity value for the next step after the insertion, you can use the SCOPE_IDENTITY function to see the identity value for the row that was just inserted. Check Books Online for further options – there are two other functions related to SCOPE_IDENTITY, but you have to be aware of the differences. And if you’re inserting multiple rows, you should consider using set-based logic to retrieve the new identity values (lots of programmers take a step-by-step approach, instead of using SQL properly).
And if you need to know the exact number of rows currently in a table: DECLARE @count INT
SELECT @count = COUNT(*) FROM mytable If you want to make sure no other process can insert rows while you’re working on it, add a transaction.
]]>