patternsqlModerate
'+' operator with one operand!
Viewed 0 times
withoneoperandoperator
Problem
How does '+' operator behave in following statement?
Is it doing string concatenation with first string blank ('' + 'taco'), or does it mean something else?
select + 'taco'; --Result is 'taco'Is it doing string concatenation with first string blank ('' + 'taco'), or does it mean something else?
Solution
How does '+' operator behave in following statement?
It is parsed as a unary plus, and ignored.
The following was given in answer to Connect item 718176 on the subject (Connect has since been retired, and no archive of this page is available):
After some investigation, this behavior is by design since + is an unary operator. So the parser accepts "+ , and the '+' is simply ignored in this case.
Changing this behavior has lot of backward compatibility implications so we don't intend to change it & the fix will introduce unnecessary changes for application code.
(Community Wiki answer generated from a comment on the question by Martin Smith)
It is parsed as a unary plus, and ignored.
The following was given in answer to Connect item 718176 on the subject (Connect has since been retired, and no archive of this page is available):
After some investigation, this behavior is by design since + is an unary operator. So the parser accepts "+ , and the '+' is simply ignored in this case.
Changing this behavior has lot of backward compatibility implications so we don't intend to change it & the fix will introduce unnecessary changes for application code.
(Community Wiki answer generated from a comment on the question by Martin Smith)
Context
StackExchange Database Administrators Q#64116, answer score: 13
Revisions (0)
No revisions yet.