T-SQL variable vs. inline conversion performance

Viewed 62

Imagine a T-SQL query that needs to determine if something is on a date. There are two versions.

declare @theDate as date = convert(date,'1900-01-01');

select * 
from someTable 
where someTable.Date = @theDate;

and

select * 
from someTable 
where someTable.Date = convert(date,'1900-01-01');

In the second example, is it running the conversion once per row? Is there any performance benefit to always putting these in variables?

1 Answers

You can take a look at the "Execution plan" of the two queries. In both cases, the cost is exactly the same.

Execution plans

Related