I'm using SQL Server 2008 R2, and I'm trying to find an efficient way to test if more than 1 row exists in a table matching a condition.
The naive way to do it is a COUNT:
IF  (   SELECT  COUNT(*)
        FROM    Table
        WHERE   Column  = <something>
    )   > 1 BEGIN
    ...
END
But this requires actually computing a COUNT, which is wasteful. I just want to test for more than 1.
The only thing I've come up with is a COUNT on a TOP 2:
IF  (   SELECT  COUNT(*)
        FROM    (   SELECT  TOP 2   0   x
                    FROM    Table
                    WHERE   Column  = <something>
                )   x
    )   > 1 BEGIN
    ...
END
This is clunky and requires commenting to document. Is there a more terse way?
 
     
    