The below three Select queries, irrespective of the Where clause having an extra space between the table alias and the column name, produce the same result. They all have the same execution plans, too. Why does the presence of a space not throw a syntax error?
DECLARE @TblX TABLE(
ColX int
,ColY float
)
-----As it normally should be
SELECT *
FROM @TblX X
WHERE X.ColX = 1
----Even this works
SELECT *
FROM @TblX X
WHERE X .ColX = 1
----And this too
SELECT *
FROM @TblX X
WHERE X. ColX = 1
Because SQL, while not entirely space-insensitive, is, let's say, "space-tolerant". For instance, try this one:
SELECT 23AB
Fun, huh? This feature came from way back in the original SQL specifications in the early 1980s when this kind of thing was still thought by some to be good (because Fortran and COBOL had similar behaviors). IIRC, it's deprecated now, but for legacy/compatibility reasons, we're still stuck with it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With