Query Sort order!

  • Thread starter Thread starter Bob Vance
  • Start date Start date
B

Bob Vance

I want to sort my column (Numbers) in a query ascending from 1 > to any
higher number, Blanks last
 
I want to sort my column (Numbers) in a query ascending from 1 > to any
higher number, Blanks last

Put in a calculated field by putting one of the expressions below in a vacnt
Field cell in your Query: if the field is a Number/Long Integer use

NZ([fieldname], 2147483647)

If it's Double, use

NZ([fieldname], 1.0E308)

and sort by this field.
 
Thanks John , it is a number/Long Integer but now im getting
1
10
2147483647
3
5
Thanks for your help Bob


John W. Vinson said:
I want to sort my column (Numbers) in a query ascending from 1 > to any
higher number, Blanks last

Put in a calculated field by putting one of the expressions below in a
vacnt
Field cell in your Query: if the field is a Number/Long Integer use

NZ([fieldname], 2147483647)

If it's Double, use

NZ([fieldname], 1.0E308)

and sort by this field.
 
Thanks John , it is a number/Long Integer but now im getting
1
10
2147483647
3
5
Thanks for your help Bob

Sounds like you're sorting it as Text - did you use Format() to cast it as a
string? If so, don't!

Please post the SQL view of your query.
 
Thanks John
SELECT NZ([SheetOrder],2147483647) AS Expr3, tblHorseInfo.SheetOrder,
tblHorseInfo.HorseID, tblHorseInfo.Status,
funGetHorse(0,tblHorseInfo.HorseID,True) AS Expr1,
funGetHorse(0,tblHorseInfo.HorseID,False) AS Name,
funGetHorse(0,tblHorseInfo.HorseID,False) AS Expr2, tblHorseInfo.Invocing,
tblHorseInfo.StatusDate
FROM tblHorseInfo
ORDER BY NZ([SheetOrder],2147483647), tblHorseInfo.SheetOrder,
tblHorseInfo.Status, funGetHorse(0,tblHorseInfo.HorseID,True);
Regards Bob
 
Thanks John

Odd. Looks like NZ is somehow casting the result as Text rather than Number.
Try

SELECT tblHorseInfo.SheetOrder,
tblHorseInfo.HorseID, tblHorseInfo.Status,
funGetHorse(0,tblHorseInfo.HorseID,True) AS Expr1,
funGetHorse(0,tblHorseInfo.HorseID,False) AS Name,
funGetHorse(0,tblHorseInfo.HorseID,False) AS Expr2, tblHorseInfo.Invocing,
tblHorseInfo.StatusDate
FROM tblHorseInfo
ORDER BY Val(NZ([SheetOrder],2147483647)), tblHorseInfo.SheetOrder,
tblHorseInfo.Status, funGetHorse(0,tblHorseInfo.HorseID,True);

Note that I removed the sort field from the SELECT statement - the query grid
way to do this is to uncheck the "show" button, you don't need to see this
field. You can also replace 2147483647 (the largest possible long integer,
xFFFFFFFF) with a smaller number, just so it's larger than any SheetOrder will
ever be; if a SheetOrder of 1000 is "ridiculously huge" just use 1000.
 
Worked Brilliant John, Thanks for your time and effort much
appreciated............Regards Bob :)

John W. Vinson said:
Thanks John

Odd. Looks like NZ is somehow casting the result as Text rather than
Number.
Try

SELECT tblHorseInfo.SheetOrder,
tblHorseInfo.HorseID, tblHorseInfo.Status,
funGetHorse(0,tblHorseInfo.HorseID,True) AS Expr1,
funGetHorse(0,tblHorseInfo.HorseID,False) AS Name,
funGetHorse(0,tblHorseInfo.HorseID,False) AS Expr2, tblHorseInfo.Invocing,
tblHorseInfo.StatusDate
FROM tblHorseInfo
ORDER BY Val(NZ([SheetOrder],2147483647)), tblHorseInfo.SheetOrder,
tblHorseInfo.Status, funGetHorse(0,tblHorseInfo.HorseID,True);

Note that I removed the sort field from the SELECT statement - the query
grid
way to do this is to uncheck the "show" button, you don't need to see this
field. You can also replace 2147483647 (the largest possible long integer,
xFFFFFFFF) with a smaller number, just so it's larger than any SheetOrder
will
ever be; if a SheetOrder of 1000 is "ridiculously huge" just use 1000.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

VBA- Excel Programming:- 0
Sorting Month-Year in Query 7
Sort order for a Report 3
Number Sorting Error 7
Question regarding queries 1
Sort order in report 2
Report sorting function 2
Sorting a Report column 3

Back
Top