9

I am working on diagnosing a problem with a legacy query in TSQL. One of the returned columns in the query is:

CASE WHEN PaidDate >= '2021-01-01' AND PaidDate <=+'2021-10-31' THEN WO ELSE 0 END AS dYTDWO, 

I have not seen "<=+" as a condition before and cannot find any reference to this online.

Can anyone provide an explanation of this? SSMS is perfectly happy with it and the query executes.

Thanks.

Solomon Rutzky
  • 70,048
  • 8
  • 160
  • 306

1 Answers1

15

TLDR: this is likely a typo1.

AND PaidDate <=+ '2021-10-31' is parsed as AND PaidDate <= (+'2021-10-31'), and the unary plus doesn't change anything so...

I'm speculating, but this probably has its roots here (emphasis mine):

Although a unary plus can appear before any numeric expression, it performs no operation on the value returned from the expression

And then they must have thought, the unary plus doesn't make sense with any non-numeric data type anyway, so why don't we just turn it into a no-op altogether, instead of coming up with data type-specific error handling.

And here you go, unary-plus whatever you want.


PS. SELECT ++++6++++++++++++++++++++++++++++5 rightly returns 11, since it's just SELECT (++++6)+(+++++++++++++++++++++++++++5), same as SELECT 6+5.


1 - Notice that "=" and "+" are on the same key.

mustaccio
  • 28,207
  • 24
  • 60
  • 76