Here is my own answer to this question (see also the update at the end):
No, there is no such unary operator in String expressions. Perhaps this is a mistake.
Explanation:
This statement is valid and generates the result below:
(No column name)
which is equivalent to executing a SELECT without using the + sign:
SELECT 'ABCDEF'
Being compiled without any errors that actually succeeded, it seems that + works like the Unary operation on a given line. However, there is no mention of such a statement in the official T-SQL documentation. In fact, under " String Operators ", + appears in two string operations, which are + (String Concatenation) and += (String Concatenation) ; but are not Unary . In addition, three operators are introduced in the " Unary Operators " section, only one of which is the + (Positive) operator. However, for this, only the one that seems relevant, it soon becomes clear that this operator also has nothing to do with non-numeric string values, since the explanation for the + (Positive) operator is explicit declares that this operator is applicable only for numeric values: " Return sets the value of a numeric expression (unary operator) . "
Perhaps this statement should successfully accept those string values ββthat are successfully evaluated as numbers, such as those used here:
SELECT +'12345'+1
When the above statement is executed, it generates a number in the output, which is the sum of both the given string, evaluated as a number, and the numerical value added to it, which is 1 here, but it can be any other amount:
(No column name)
However, I doubt this explanation is correct, as it goes up to the questions below:
Firstly, if we agree that this explanation is true, then we can conclude that expressions such as +'12345' are evaluated by numbers. If so, why can these numbers appear in string-related functions like DATALENGTH , LEN , etc. You could see the expression:
SELECT DATALENGTH(+'12345')
quite fair, and this leads to the following:
(No column name)
which means that +'12345' is evaluated as a string, not a number. How can this be explained?
Secondly, although similar statements with the operator - , for example:
`SELECT -'ABCDE'`
or even this:
`SELECT -'12345'`
generates an error below:
Invalid operator for data type. Operator equals minus, type equals varchar.
Why should it not generate an error for such cases when the + operator was mistakenly used with a non-numeric string value?
So, these two questions do not allow me to accept the explanation that this is the same + (unary) operator that was introduced into the documentation for numeric values. Since there is no other mention of this elsewhere, perhaps this is intentionally added to the language. Maybe a mistake.
The problem looks more serious when we see that for operators such as this, an error is not generated:
SELECT ++++++++'ABCDE'
I do not know if there are any other programming languages ββthat accept such statements. But if there is, it would be nice to know for what purpose they use the + (unary) operator applied to the string. I can not imagine any use!
UPDATE
It says that it was a bug in earlier versions, but it will not be fixed due to backward compatibility:
After some research, this is design behavior, since + is a unary operator. Therefore, the parser accepts "+", and "+" is simply ignored in this case. Changing this behavior has many consequences of backward compatibility, so we do not intend to change it, and the fix will make unnecessary changes to the application code.