Solved

Why Negative Numbers don't sort correctly

Posted on 2002-05-09
9
275 Views
Last Modified: 2008-03-06
I'm using the query below and the numbers are sorting as if all were positive numbers.  The sign is not being considered so negative numbers sort as if there was no sign.

SELECT [AA CostperBeq_Bll].AreaName, [AA CostperBeq_Bll].CostBeq
FROM [AA CostperBeq_Bll]
ORDER BY Left(AreaName,1), [AA CostperBeq_Bll].CostBeq DESC;


What do I need to do?

Thanks

Elton
0
Comment
Question by:katzwhite
9 Comments
 
LVL 2

Expert Comment

by:Bangerter
ID: 6999645
in your order by statment try:

ORDER BY val(left(areaname, 1))
0
 
LVL 2

Expert Comment

by:Bangerter
ID: 6999651
if it doesnt like that you could create another field in your query: MyOrder: val(left(areaname,1))

and then set your orderby to: Order By MyOrder

just a thought. are you sure that your left command is picking up the negative sign? where your parameter is only 1 it will only pick up the first character so if you have '-1' the left will only pick up the '-' and not the '1' as well.

is areaname a text field or a numeric field?
0
 

Author Comment

by:katzwhite
ID: 7000200
Sorry, I didn't explain better.   [AA CostperBeq_Bll].CostBeq is the numberic field that isn't sorting negatives property. AreaName is a text field being ordered by the first letter only and it is working properly.

Output from the sort can be seen at http://www.KatzWhite.com/SortError.gif

Thanks for the help.

Elton
0
U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

 
LVL 5

Expert Comment

by:gwgaw
ID: 7000494
Your query sorts by AreaName first and then by CostBeq. Changing

ORDER BY Left(AreaName,1), [AA CostperBeq_Bll].CostBeq DESC;

to

ORDER BY [AA CostperBeq_Bll].CostBeq DESC, Left(AreaName,1);

will sort the numbers correctly. However, AreaName will no longer be in alphbetical order.
0
 
LVL 9

Expert Comment

by:Volibrawl
ID: 7000860
Well, those might be queries that would work, unfortunately neither provides the order that katzwhile wants.

I see nothing wrong with your query and it should give you the correct results.  Check:

1. The type of field for COSTBEQ, either number or text should work ...but check it
2. Your negative number may not be entered correctly, re-enter it.
3. Try changing to ascending to see if it works with your data.

good luck
0
 

Author Comment

by:katzwhite
ID: 7001604
I checked the originating table and its set up as double.  CostBeq is the output of a query that totals the purchases table by area.  No formating is applied to the CostBeq.

converted from A97 where I think its working correctly and am now running under Acess 2000.

I'll try sorting on Left(AreaName,1),  Left([AA CostperBeq_Bll].CostBeq,1),  [AA CostperBeq_Bll].CostBeq DESC;  and see if that will do the trick.

Looks like a bug in the sort to me.

Thanks

Elton
0
 
LVL 1

Expert Comment

by:scorp8
ID: 7001699
Have you tried changing the data type in the query?

What's the current datatype in the table it's pulling from?

If you use CInt, CDbl, etc. it changes your datatype for that particular field in the query.

Example below:

SELECT [AA CostperBeq_Bll].AreaName, [AA CostperBeq_Bll].CostBeq
FROM [AA CostperBeq_Bll]
ORDER BY Left(AreaName,1), CInt([AA CostperBeq_Bll]).CostBeq DESC;


Place CInt([]) in front of [AA CostperBeq_Bll]

scorp8

0
 

Author Comment

by:katzwhite
ID: 7108646
My own
suggestion,  Left(AreaName,1),  Left([AA CostperBeq_Bll].CostBeq,1),  [AA CostperBeq_Bll].CostBeq DESC;  did the trick.

Without " Left([AA CostperBeq_Bll].CostBeq,1)". it sorts as if all the numbers are positive.

Best

Elton

0
 
LVL 5

Accepted Solution

by:
Netminder earned 0 total points
ID: 7108853
User resolved; points refunded and question closed.

Netminder
CS Moderator
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When you are entering numbers in a speadsheet, and don't remember what 6×7 is, you just type “=6*7" instead. It works in every cell! This is not so in Access. To enter the elusive 42 in a text box, you have to find a calculator, and then copy the re…
QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.

816 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now