How does '+' operator behave in following statement?
select + 'taco'; --Result is 'taco'
Is it doing string concatenation with first string blank ('' + 'taco'), or does it mean something else?
It is parsed as a unary plus, and ignored, as described in this Connect item. While not strictly correct, the behaviour will not be changed because it would "introduce unnecessary changes for application code" and has "backward compatibility implications".
(Originally posted as a comment to the question by Martin Smith)
The string concatenation operator "+", by definition, "concatenates two or more" strings. http://technet.microsoft.com/en-us/library/ms177561.aspx
This query executes successfully because the implied second string is the non-null concatenation identity (empty string).
This works in the same way as the operator in
The syntax is allowed because of the need for expressions such as
Consider the Execution Plans generated by these SQL Statements (I added top(1) to obtain a plan):
The execution plans are identical. The "Compute Scalar" operator does not reveal any concatenation activity. The Query Optimizer simplifies the identity concatenation expression before execution.