I am updating some code (which i did not write) that first runs a query such as
SELECT COUNT(*)
FROM dbo.APP_Person as Person
WHERE Person._pk > 0
AND Person.last_name LIKE 'LName%'
AND Person.first_name LIKE 'FName%'
AND Person._pk IN (SELECT _pk FROM dbo.APP_PersonView )
If the resulting count is not too large, it later runs much the same query, but with SELECT Person._pk in place of SELECT COUNT(*). Otherwise the user is told to refine the set of selections and try again.
(The fields to be checked, and the values to compare to, are from user input.)
Is there a good reason not to simply run the second form and look at the size of the result, so i don't need to run the query twice? will the SELECT COUNT(*) be that much faster than SELECT Person._pk (the primary key)?
This will run under SQLserver 2005 or later, probably 2008 or later. The table is fairly large.