Hi Ryan,
There're two ways to get total records count in SQL Server table:
1. SELECT COUNT(*) FROM mytable
Produces correct count but may take long on tables with a lot of records.
2. SELECT rowcnt FROM sysindexes WHERE id=OBJECT_ID('dbo.mytable') and indid < 2
Fast but result isn't relaible because it's based on data stored in sysindexes tables which may or may not be current.
With parameters you specified SP_TABLE_VALIDATION uses the first method (SELECT COUNT(*)) to get total record count. So you may just use SELECT COUNT(*).
>Doug's post about a general counting SP got me thinking about a function I wrote a long time ago in VFP that will do a fast total record count on a table in SQL Server (sorry, not filtered but more like the RECCOUNT() function of VFP). I thought I would share it.
>
>I am not sure how this could be made to work as stored procedure, but as a VFP function it works great. It would be interesting if someone couLd make this a SP that either returned a result set of the record count or an output parameter.
>
>
>** gnSql is assumed to be a public connection handle to SQL Server.
>**
>** The same system SP is called twice once with 0 as the count parameter and
>** then as null for the second call. SQL Server could report incorrect
>** results if only one call is made, see SP_TABLE_VALIDATION in BOL.
>**
>FUNCTION SQLRecCount(cTableName)
>LOCAL nCount
>nCount = 0
>IF SQLEXEC(gnSql,;
> "{Call SP_TABLE_VALIDATION ('" + cTableName + "',?@nCount)}") > 0
> nCount = NULL
> IF SQLEXEC(gnSql,;
> "{Call SP_TABLE_VALIDATION ('" + cTableName + "',?@nCount)}") > 0
> RETURN INT(nCount)
> ENDIF
>ENDIF
>
--sb--