Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - order by price problem
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

order by price problem

 Post Reply Post Reply
Author
rocketdawg View Drop Down
Newbie
Newbie
Avatar

Joined: 03 August 2004
Status: Offline
Points: 17
Post Options Post Options   Thanks (0) Thanks(0)   Quote rocketdawg Quote  Post ReplyReply Direct Link To This Post Topic: order by price problem
    Posted: 05 February 2005 at 11:35am
When displaying a list of cd's and their prices, the list is displayed in this order - ie:
 
1.40
1.50
2.00
21.00
4.50
45.90
7.50
 
etc
 
So, how do you get it to display in actual order of price? 7.00 should come before 21.00
 
Access 2000
 
my select statement:
 
strSQL = "SELECT * FROM products WHERE type = ""cd"" ORDER BY productPrice"
 
I'm sure it must be something simple, I just can't seem to work this one out. Thank you for your help.
Back to Top
dpyers View Drop Down
Senior Member
Senior Member


Joined: 12 May 2003
Status: Offline
Points: 3937
Post Options Post Options   Thanks (0) Thanks(0)   Quote dpyers Quote  Post ReplyReply Direct Link To This Post Posted: 05 February 2005 at 11:50am
is product price a currency field or a text field?

Lead me not into temptation... I know the short cut, follow me.
Back to Top
rocketdawg View Drop Down
Newbie
Newbie
Avatar

Joined: 03 August 2004
Status: Offline
Points: 17
Post Options Post Options   Thanks (0) Thanks(0)   Quote rocketdawg Quote  Post ReplyReply Direct Link To This Post Posted: 05 February 2005 at 12:03pm

productprice is a text field.

I tried this just to see what would happen:
 
strSQL = "SELECT * FROM products WHERE type = ""cd"" ORDER BY (productPrice*100)"
 
and it worked! It now orders correctly by price, and, miraculously it leaves the decimal point in the right place in the display table.
 
You raise a question in my head though. Why does a math calculation work on a text field? I would think that it would have to be a numeric field to have math performed on it. Or would it be easier just to accept the fact that it does, and move on? I only ask to understand, and perhaps help someone else with the same problem.
 
 
Back to Top
Gullanian View Drop Down
Senior Member
Senior Member
Avatar

Joined: 04 January 2002
Location: England
Status: Offline
Points: 4373
Post Options Post Options   Thanks (0) Thanks(0)   Quote Gullanian Quote  Post ReplyReply Direct Link To This Post Posted: 06 February 2005 at 12:14am
I think access is clever in datatypes and allows executions such as that, although it's better practise to make mathamatical operations in sql queries be run on numerical datatypes for database compatability if you ever choose to move.
Back to Top
michael View Drop Down
Senior Member
Senior Member
Avatar

Joined: 08 April 2002
Location: United States
Status: Offline
Points: 4670
Post Options Post Options   Thanks (0) Thanks(0)   Quote michael Quote  Post ReplyReply Direct Link To This Post Posted: 06 February 2005 at 10:48am
actually it is ok to do math operations on text fields but you need to built in some error handling. Access automatically tries a cast on that field, but better practice is to make the field numeric.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down

Forum Software by Web Wiz Forums® version 12.08
Copyright ©2001-2026 Web Wiz Ltd.


Become a Fan on Facebook Follow us on X Connect with us on LinkedIn Web Wiz Blogs
About Web Wiz | Contact Web Wiz | Terms & Conditions | Cookies | Privacy Notice

Web Wiz is the trading name of Web Wiz Ltd. Company registration No. 05977755. Registered in England and Wales.
Registered office: Web Wiz Ltd, Unit 18, The Glenmore Centre, Fancy Road, Poole, Dorset, BH12 4FB, UK.

Prices exclude VAT at 20% unless otherwise stated. VAT No. GB988999105 - $, € prices shown as a guideline only.

Copyright ©2001-2026 Web Wiz Ltd. All rights reserved.