I’ve got a query with about 5 unions; at the end I’ve got an order by on a DateTime field (so I’m 100% definitely not ordering on a varchar) – and it seems the order is screwed up for some reason, any ideas? There’s no identifiable pattern either 🙁
SELECT a, b, c, DateField
FROM whatever
UNION
SELECT a, b, c, DateField
FROM whatever
UNION
SELECT a, b, c, DateField
FROM whatever
Order By convert(DateTime, DateField, 111) -- The convert is just to make doubly sure about the data type
1 Answer