Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 4 of 4 total
Thread Index problem
Wed, Jul 20 2011 10:13 AMPermanent Link

Stagiaire12

Hello,

I have 2 sort orders in my table, ASC and DESC:

NULL               9
NULL               8
6                     7
7                     6
8                     NULL
9                     NULL

Is it possible to get the NULL value always on top in the table? In the index settings I see no option for it.

Thanks
Wed, Jul 20 2011 10:26 AMPermanent Link

Roy Lambert

NLH Associates

Team Elevate Team Elevate

Stagiaire12


I think the answer is no but if you're using SQL rather than tables you can cheat and use COALESE

ORDER BY COALESCE(sortcol,9999999) DESC

will put NULLs at the top as will

ORDER BY COALESCE(sortcol, -99999) ASC

Roy Lambert [Team Elevate]
Fri, Jul 22 2011 4:47 PMPermanent Link

Chris B

Stagiaire12 wrote:

Hello,

I have 2 sort orders in my table, ASC and DESC:

NULL               9
NULL               8
6                     7
7                     6
8                     NULL
9                     NULL

>>Is it possible to get the NULL value always on top in the table? In the index settings I see no option for it.

Alternatively, order by

ORDER BY CASE WHEN ISNULL(FieldName) THEN 0 ELSE 1 END, ColumnName
Mon, Jul 25 2011 2:19 PMPermanent Link

Tim Young [Elevate Software]

Elevate Software, Inc.

Avatar

Email timyoung@elevatesoft.com


<< Is it possible to get the NULL value always on top in the table? In the
index settings I see no option for it. >>

You can do so, but you have to do it in a "roundabout" way.  What you do is
create a generated or computed column that includes an expression similar to
what Roy and Chris have proposed, and then create an index on this column
instead.  That will give you an index with a custom sort for the NULL
values.

--
Tim Young
Elevate Software
www.elevatesoft.com
Image