Click to See Complete Forum and Search --> : Order by, except the value ""


gerjanschoemake
11-08-2005, 05:47 AM
I want to order the output from my database by prices,
like
0.235
0.345
0.478

There are some products with the value "" or "0", logical they show up first:
0
0
0.234
0.45

What I want is to order by the price, except the products with no value have to appear at the end. like:
0.234
0.45
0
0

Is this possible?

Ubik
11-08-2005, 11:41 AM
Try something like:

select * from datatable where price > 0 order by price
UNION
select * from datatable where price = 0

Bullschmidt
11-10-2005, 04:01 PM
Or with a calculated field (assuming an Access database) here's a SQL statement that orders records showing lowest totals first but putting any totals that are 0 or blank last:

strSQL = "SELECT * FROM tblInv ORDER BY IIf(IsNull([InvTotal])Or([InvTotal]=0),True,False) DESC, tblInv.InvTotal"

gerjanschoemake
11-11-2005, 08:14 AM
tnx! that will work better because off the length of my sql strings.

Bullschmidt
11-11-2005, 02:27 PM
You're welcome :)