Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Why Negative Numbers don't sort correctly

Posted on 2002-05-09
9
Medium Priority
?
315 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

Question has a verified solution.

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

Code that checks the QuickBooks schema table for non-updateable fields and then disables those controls on a form so users don't try to update them.
Explore the ways to Unlock VBA Project Password Excel 2010 & 2013 documents. Go through the article and perform the steps carefully to remove VBA Excel .xls file.
In Microsoft Access, when working with VBA, learn some techniques for writing readable and easily maintained code.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

610 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