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 wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sorting on the difference between two fields 1

Status
Not open for further replies.

liark

Programmer
Apr 18, 2000
36
GB
I have two fields in a table..... in my select statement, I'd like to select a variable as THE DIFFERENCE between these two fields. Is this possible?

i.e.

Code:
SELECT (abc - def) AS ghi FROM table
WHERE....

this is the code:

Code:
<cfquery name="gettopmovers" datasource="abc" maxrows=10>
	SELECT surname, (lws - tws) as topmove from punters
	WHERE openfield > 0
	ORDER by topmove DESC
</cfquery>

as a result, I get

Code:
Error Diagnostic Information
ODBC Error Code = 07001 (Wrong number of parameters)


[Microsoft][ODBC Microsoft Access Driver] Too few parameters. Expected 1.

Hint: The cause of this error is usually that your query contains a reference to a field which does not exist. You should verify that the fields included in your query exist and that you have specified their names correctly.


The error occurred while processing an element with a general identifier of (CFQUERY), occupying document position (2:4) to (2:64).

The fields do exist in the table.

Thanks for your help.


Liark


 
yes you can use a column alias in the SELECT, the problem is, in microsoft access you cannot use the alias in the ORDER BY
Code:
SELECT surname
     , (lws - tws) as topmove 
  from punters
 WHERE openfield > 0
ORDER 
    by (lws - tws) DESC

r937.com | rudy.ca
 
Brilliant. Thanks r937.

Liark


 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top