Search code examples
sql-servertemp-tables

Microsoft SQL Server 2005 check if temporary table empty


Is there a fast/efficiency way to check if a table is empty?

DECLARE @StartEndTimes TABLE
(
    id bigint,
    StartTime datetime,
    EndTime datetime
)

IF @StartEndTimes IS NOT NULL

Solution

  • Rather than counting you can;

    if exists (select id from @StartEndTimes)
       set @has_stuff = 1
    

    Which will return as soon as it hits a row.