How operator> + differs from> = in SQL Server 2012

Throughout the error today, I ran an SQL statement to filter some elements by date, for simplicity we will say that I used

SELECT * FROM [TableName] WHERE [RecordCreated] >+ '2016-04-10' 

Only after the operator started, I realized that I used> + instead of> =, now I was confused, as I would expect an error.

I tried a couple of other options like

 >- -- Throws an error <+ -- Ran successfully <- -- Throws an error 

The number of rows returned was exactly the same if I used> = or> +

After searching the Internet, I could not find the documentation that directly looked at this syntax only when the two statements are used separately.

The RecordCreated column is a datetime .

Is this just the syntax for a possible common error, or is it potentially trying to specify a date as a numeric value?

+7
sql-server tsql
source share
2 answers

This seems to be a bug with the + operator.

According to updates from the Microsoft team,

After some research, this behavior is constructive, since + is a unary operator. Therefore, the parser accepts "+", and "+" is simply ignored in this case. Changing this behavior has a lot of backward compatibility, so we do not intend to change it & the fix will make unnecessary changes for the application code.

You can find a really good RGO answer on your own question here .

+1
source share

The result should not coincide with "> =" and "<=", but with ">" and "<". Just checked, and rowcound will change to 2 - the first and last elements are deleted.

-2
source share

All Articles