SQL: Addition or concatenation
select ‘0001’ + 1
What is the result?
Logically, it could be ‘00011’ or 2. It should be ‘00011’ if the + is interpreted as concatenation, , and 2 if the + is iterpreted as addition and (‘0001’ is implicitly cast to a number).
The result is 2. Reminder, addition takes precedence over concatenation.
edit: Upon further examination, the issue isn’t operator precedence but data type precedence.
The data type precedence rules determine which operands get converted to the other.
- sql_variant (highest)
- binary (lowest)