Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

order query results by a calculated field.....PLEASE!!!!!!!!!

Status
Not open for further replies.

Herbie1

Technical User
Oct 14, 2001
2
GB
I am using a VB6 App to query an ACCESS 97 database.
I would like to use two of the database fields to perform a calculation. The answer, a percentage, is then stored in an alias named 'LOSS'.
However, when I attempt to use the new alias LOSS in the ORDER BY section of my query, it does not work.The query produces the correct results but does not place them in the desired order.

My query is shown below. Somebody PLEASE Help!!!!!!!!!

querystring = "select top 10 CLOSE,OPEN,LEGEND,(CLOSE/(OPEN/100))-100 as LOSS from PRICEDATA where DATE between # " & querydate & "# and # " & querydate1 & "# order by (CLOSE/(OPEN/100))-100 as LOSS desc"
 

Remove the alias on the calculated value in the Order By clause.

querystring = "select top 10 CLOSE,OPEN,LEGEND,(CLOSE/(OPEN/100))-100 as LOSS from PRICEDATA where DATE between # " & querydate & "# and # " & querydate1 & "# order by (CLOSE/(OPEN/100))-100 Desc"

HTH Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Thanks for the reply, Terry.

I've tried removing the alias from the order by clause, but now I simply get an error "unknown".
I've used the debug window to check the values of the alias LOSS and it definitely works, but I can't order the results!

Any ideas?

Herbie1
 

Is there more to the error message than "unknown?"

I note in your post that you have a space between the # and the " as in # " & querydate. If those spaces actually exist, remove them and see if that makes a difference. Otherwise, post a more complete error message if available. Terry L. Broadbent
FAQ183-874 contains tips for posting questions in these forums.
NOTE: Reference to the FAQ is not directed at any individual.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top