I am running this query on SQL Server 2012:
select 'weird'
where '' = 0
It's returning 'weird'
.
As far as I understand, ''
is quite different from 0
. So please explain why the above happens.
Thanks
I am running this query on SQL Server 2012:
select 'weird'
where '' = 0
It's returning 'weird'
.
As far as I understand, ''
is quite different from 0
. So please explain why the above happens.
Thanks
So, taking a look at the data types where they stand in the
WHERE
clauseThey return
int, varchar
respectively.When comparing two different data types, the data type with the lower precedence will convert to the higher precedence, per MSDN.
In this case,
Varchar
converts toint
.The above returns
0
.Thus