I’ve tried looking for the answer, and read many threads on this site, but still can’t find the answer I’m looking for.
I am trying to sort a series of numbers that are real look-ups and also one * which isn’t, I can sort fine when I don’t need to add the fake * but not after.
I have tried
SELECT DISTINCT MasterTable.ClassName, MasterTable.ClassYear
FROM MasterTable
UNION ALL
SELECT DISTINCT "*" As [ClassName], "1" As [ClassYear]
FROM MasterTable
ORDER BY MasterTable.ClassYear;
And
SELECT DISTINCT MasterTable.ClassName, MasterTable.ClassYear
FROM (
SELECT DISTINCT MasterTable.ClassName, MasterTable.ClassYear FROM MasterTable
UNION
SELECT DISTINCT "*" As [ClassName], "1" As [ClassYear] FROM MasterTable
)
ORDER BY MasterTable.ClassYear;
But both return the ClassYear as 1, 10, 12, 8… rather than 1, 8, 10, 12….
Any help would be much appreciated,
Thanks 🙂
MasterTable.ClassYear is varchar so it will sort as a string.
You’ll have to convert it in the query or fix the column type.
For the 2nd clause, you also need only:
However, you can “cheat” and do this. Here 1 will be int and will force a conversion to int from the 1st clause because