Reputation: 682
Looking at the return value for year()
on SQL Server and it seems to be an int.
Then why does the following statement return 'equal'?
Why does the comparison operator consider int 2002
and string '2002'
equal? Should it?
select
case
when year('2002-01-14 00:00:00.000') = '2002' then 'equal'
else 'not equal'
end
Upvotes: 2
Views: 476
Reputation: 35323
Because SQL server is implicitly casting '2002' to the data type of of the first value in the equality check. (int) in this case
Upvotes: 2