This is the list that you are after DataType Priority
In your examples:
WHERE quantity > '3'
'3' is converted to int, matching the number
WHERE quantityTest > 3
No casting required
WHERE date = 20120101
20120101 because the number is added to a date that is too large. eg.
select cast(20120101 as datetime)
It is different from
WHERE date = '20120101'
If the date as a string can be cast.
If you go to the third part of the CAST and CONVERT links in the Implicit Conversions section, the implicit conversion table is resolved. Just because it is allowed does not mean that it will work, for example (20120101 β datetime).
source share