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!

Looking up value in a range 1

Status
Not open for further replies.

v100bhoy

IS-IT--Management
Mar 3, 2010
2
GB
I have a table:
Code:
MilesFrom  MilesTo  Charge
0          2        2.5
3          100      0.5
101        500      0.25
I am wanting to lookup a value in the ranges and return the charge.
Ie a value of 10 would match to 2 x 2.5 and then 8 x 0.5.

I can't get my head around how to do this in CF, any suggestions much appreciated.
 
Try:
Code:
<cfquery name="getCharge" datasource="MyDataSource">
 Select Charge 
 From Mytable
 Where MyVal>=MilesFrom  
 And MyVal<=MilesTo
</cfquery>

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Lyndon.
I knew there was a simple thing I was missing.
thanks for the help
 
No problem; I'm glad to help.

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Where MyVal>=MilesFrom
And MyVal<=MilesTo

Though it works either way, IMO it is a bit more standard to place the variable on the right side of the operators. At least in this type of query. (Obviously substitute cfqueryparam ...)

WHERE MilesFrom <= #someValue#
AND MilesTo >= #someValue#


----------------------------------
 
cfSearching, you caught me. I'm left-handed. LOL

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top