Web Wiz - Green Windows Web Hosting

  New Posts New Posts RSS Feed - Math with columns in SQL??
  FAQ FAQ  Forum Search   Events   Register Register  Login Login

Math with columns in SQL??

 Post Reply Post Reply
Author
FLATLINE View Drop Down
Groupie
Groupie
Avatar

Joined: 08 July 2002
Location: Israel
Status: Offline
Points: 142
Post Options Post Options   Thanks (0) Thanks(0)   Quote FLATLINE Quote  Post ReplyReply Direct Link To This Post Topic: Math with columns in SQL??
    Posted: 31 May 2004 at 4:35am

Hello,

I need to open a SQL query and order it by the multiplication of two fields. I couldn't do it using the string below, and I don't want to add an extra column to hold the results. Is this possible? How?

strSQL = "SELECT * FROM table ORDER BY field1*field2 DESC;"

Thanks.

Visit my site: DarkGreen HQ
Back to Top
Mart View Drop Down
Senior Member
Senior Member
Avatar

Joined: 30 November 2002
Status: Offline
Points: 2304
Post Options Post Options   Thanks (0) Thanks(0)   Quote Mart Quote  Post ReplyReply Direct Link To This Post Posted: 31 May 2004 at 4:36am
Is this access or MSSQL?
Back to Top
FLATLINE View Drop Down
Groupie
Groupie
Avatar

Joined: 08 July 2002
Location: Israel
Status: Offline
Points: 142
Post Options Post Options   Thanks (0) Thanks(0)   Quote FLATLINE Quote  Post ReplyReply Direct Link To This Post Posted: 31 May 2004 at 4:38am
MSAccess 2000
Visit my site: DarkGreen HQ
Back to Top
Phat View Drop Down
Senior Member
Senior Member


Joined: 23 February 2003
Status: Offline
Points: 386
Post Options Post Options   Thanks (0) Thanks(0)   Quote Phat Quote  Post ReplyReply Direct Link To This Post Posted: 31 May 2004 at 6:43am
Try

SELECT Table1.*, [Table1]![f1]*[Table1]![f2] AS Total
FROM Table1
ORDER BY [Table1]![f1]*[Table1]![f2];

Back to Top
FLATLINE View Drop Down
Groupie
Groupie
Avatar

Joined: 08 July 2002
Location: Israel
Status: Offline
Points: 142
Post Options Post Options   Thanks (0) Thanks(0)   Quote FLATLINE Quote  Post ReplyReply Direct Link To This Post Posted: 31 May 2004 at 9:42am
why do you use brackets and an exclamation mark? And if you're querying the result as Total then why do you still order the recordset using the multiplication?
Visit my site: DarkGreen HQ
Back to Top
Phat View Drop Down
Senior Member
Senior Member


Joined: 23 February 2003
Status: Offline
Points: 386
Post Options Post Options   Thanks (0) Thanks(0)   Quote Phat Quote  Post ReplyReply Direct Link To This Post Posted: 31 May 2004 at 8:35pm
That sql was built in access with the query builder. There may be other ways to do it but that is what access gives as an output.

Back to Top
FLATLINE View Drop Down
Groupie
Groupie
Avatar

Joined: 08 July 2002
Location: Israel
Status: Offline
Points: 142
Post Options Post Options   Thanks (0) Thanks(0)   Quote FLATLINE Quote  Post ReplyReply Direct Link To This Post Posted: 31 May 2004 at 9:28pm
It works great. Thanks. 

Edited by FLATLINE
Visit my site: DarkGreen HQ
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.