February 22, 2010 at 11:18 am
Steve,
As GilaMonster mentioned that the optimizer "has no idea if the between is going to affect 1 row, or the entire table" , you can first try to give it some idea of the range by adding this line first: where (TRANS_DATE <= @dEndDate)
So you're where clause actually becomes:
where (TRANS_DATE <= @dEndDate)
and (TRANS_DATE >= @dStartDate and TRANS_DATE <= @dEndDate )
Hope this helps,
Wahib Omran
March 30, 2010 at 6:07 am
Sometimes there is a need to get the record count of every table in a SQL Server database. The common method used for achieving this is doing a select count(*) from table_name but this can create a lot of overhead in large tables present in large databases.
The record count of every user table is maintained in the sysindexes system table . There is a indid column in the sysindexes table and every user table will have an entry in sysindexes with indid value of either 0 or 1 , but not both. The rowcnt column corresponding to indid 0 or 1 gives us the total row count of a table.
The User Defined Function given below shows how to retrieve row count for a table by making use of sysindexes.
Viewing 2 posts - 31 through 31 (of 31 total)
You must be logged in to reply to this topic. Login to reply