I have an ORDER BY clause which order a result set of grouped values.
What I would like the ORDER By to do is result in the No KS2 row being at the top.
The values are conditionally populated from three different columns, but the values are from the same set across all three columns.
The values are null, a string of length zero, 1c, 1b, 1a, 2c, 2b, 2a, 3c.... 5a, 6c, 6b, 6a
Currently my ORDER BY clause brings out the values by ordering baased on the left of the value and the right of the values DESC.
And example result set would be:
2a
3c
3b
4c
4b
4a
5c
5b
No KS2
Here is an example of what I would like:
No KS2
2a
3c
3b
4c
4b
4a
5c
5b
The code I have currently is here:
ORDER BY
LEFT(
CASE Name
WHEN 'English' THEN
CASE WHEN [Ks2en]=NULL OR [Ks2en]='' THEN
'No KS2'
ELSE
[Ks2en]
END
WHEN 'Mathematics' THEN
CASE WHEN [Ks2ma]=NULL OR [Ks2ma]='' THEN
'No KS2'
ELSE
[Ks2ma]
END
ELSE
CASE WHEN [Ks2av]=NULL OR [Ks2av]='' THEN
'No KS2'
ELSE
[Ks2av]
END
END,1),
RIGHT(
CASE Name
WHEN 'English' THEN
CASE WHEN [Ks2en]=NULL OR [Ks2en]='' THEN
'No KS2'
ELSE
[Ks2en]
END
WHEN 'Mathematics' THEN
CASE WHEN [Ks2ma]=NULL OR [Ks2ma]='' THEN
'No KS2'
ELSE
[Ks2ma]
END
ELSE
CASE WHEN [Ks2av]=NULL OR [Ks2av]='' THEN
'No KS2'
ELSE
[Ks2av]
END
END,1) DESC