var sidebar_align = 'right';
var content_container_margin = parseInt('290px');
var sidebar_width = parseInt('270px');
Unanswered: How to ORDER this secuence??
I would like to order the secuence of numbers:
Name | Age
Silvia -->Null value
and i would like the next solution:
Name | Age
Rachel 19 --> Low value
John 25 --> High value
Silvia ---> Null value
in other word I like that the null values will be at the end
of the query. Is it possible?
select * from your_table
order by case when age is null then 999 else age end
ORDER BY IIF(ISNULL(age), 999, age) ASC
kiko123456 - yours will not fly, but the concept is the same.
ORDER BY ISNULL(age, 999) ASC
okay, to be fair, this problem does apparently deal with people and their ages, and it's unlikely you'll ever get a person with an age higher than 999, but just the same, the method is flawed, and may fail if you were dealing with some other quantity where you couldn't be quite so sure that you were generating a "nothing-will-
so do it this way:
select name, age
case when age is null then 1 else 0 end
that's a good observation, except we were talking about people's age, not everything else. also, your case statement needs to be reversed, not when age is null then 1, but rather then 0 else 1.
yes, i did concede we were talking about age, and that 999 is likely good enough, my point was to develop better habits
and when age is null, you do want 1, not 0, because that will sort the nulls last
Okay, how about
ORDER BY ISNUMERIC(age) desc, Age ASC
Online help doesn't indicate what ISNUMERIC returns with a Null so I can't test this at the moment.
isnull and isnumeric have the drawback that they aren't standard
i still prefer
order by case when age is null then 1 else 0 end, age