Question

I don't know how to test the performance of these two way of getting what i want.

select * 
from table 
where column like '%'+left(getdate(),11)+"%

select * 
from table 
where
              DATEPART (DD, column) = DATEPART (DD, GETDATE())  
      AND     DATEPART (MM, column) = DATEPART (MM, GETDATE())  
      AND     DATEPART (YY, column) = DATEPART (YY, GETDATE())
Was it helpful?

Solution

Typically in SQL you can just loop through executing the statement however many times and calculating the time to execute for each statement. Do this a few times to be sure and compare the results.

declare @startTime datetime
declare @endTime datetime
declare @execution BIGINT

SET @execution = 0

set @startTime = GETDATE()
while (@execution < 1000000)
begin    
    --TestSyntax goes here


    SET @execution = @execution + 1

end
set @endTime = GETDATE()

SELECT DATEDIFF(ms, @endTime, @startTime) AS 'TimeToExecute'

Also know, string comparisons are typically slower in all languages.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top