Solved

Why Negative Numbers don't sort correctly

Posted on 2002-05-09
9
258 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
 
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
IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

This article is a continuation or rather an extension from Cascading Combos (http://www.experts-exchange.com/A_5949.html) and builds on examples developed in detail there. It should be understandable alone, but I recommend reading the previous artic…
Regardless of which version on MS Access you are using, one of the harder data-entry forms to create is one where most data from previous entries needs to be appended to new records, especially when there are numerous fields and records involved.  W…
Familiarize people with the process of utilizing SQL Server views from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Access…
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…

747 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

16 Experts available now in Live!

Get 1:1 Help Now