Hello,
We noticed some odd behaviour of the ORDER BY clause inside the following pieces of code:
-- Batch 1:
DECLARE@iINT = 0
SELECT@i= @i+a
FROM (SELECT 1aUNION ALLSELECT 2 UNIONALLSELECT 3)x
ORDERBY a
SELECT@i
GO
-- Batch 2:
DECLARE@iINT = 0
SELECT@i= @i+a
FROM (SELECT 1aUNION ALLSELECT 2 UNIONALLSELECT 3)x
ORDERBY 1
SELECT@i
Does anyone know why in Batch 2 example only the last value of the UNION is added to the @i variable ?