Microsoft SQL Server 2005 checks to see if a temporary table is lost

Is there a quick / efficient way to check if a table is empty?

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

IF @StartEndTimes IS NOT NULL

      

+2


a source to share


2 answers


Instead of counting, you can:

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

      



which will return as soon as it hits the string.

+8


a source


I think your best bet might be COUNT



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

SELECT COUNT(1) FROM @StartEndTimes

      

+1


a source







All Articles