I have patched together a shopping cart, operating on CF8, and am now trying to add shipping. The client wants the shipping charges based on the cost of item, ie:
0-$499 is $20
$500 – $999 is $25.00
$999 – up $45
I built an access table (simplified) with the following rows
Price_min, Price_max,ship_cost
The idea is to query the subtotal from the price_min and Price_max to determine the shipping cost:
<cfquery name="getInfo" datasource="#application.databasePRD#">
select ship_cost, price_min,price_max
from shipping
where price_min >= #form.subtotal# and price_max <= #form.subtotal#>
</cfquery>
</cfif>
<cfoutput query="getInfo">
#ship_cost#
</cfoutput>
Alas, I get the following error:
Syntax error (missing operator) in query expression ‘price_min >= 29 and price_max <= 29'.
What am I doing wrong?
Did you try the comparison operators in a different order? Sometimes databases care about this and different databases sometimes want them in a different way.
I.E.
where price_min => #form.subtotal# and price_max =< #form.subtotal#
Also, have you investidated the values of the form.subtotal and confirmed that it is just the number you expect it to be and that it does not contain any other characters?
Yes, I tried moving the comparison operators and verified the that the number was actually a number by itself. I even broke the code out to a new form and simplified the script. I created a new form and sent the price to the script and still got the "Syntax error (missing operator) in query expression" error
I think ilssac is correct here... your initial WHERE clause is wrong.
Consider a record where price_min is 0 and price_max is 499, and the subtotal is 250.
Your query is [where price_min >= #form.subtotal# and price_max <= #form.subtotal#]
Which is [where 0 >= 250 and 499 <=250]
Clearly this is never going to return anything.
Reverse the operators like ilssac has done and you should be ok.
Rickaclark54,
I expected your query to work. However, from your explanation, I expected the operators to be the other way round! That is, this query:
<cfquery name="getInfo" datasource="#application.databasePRD#">
select ship_cost, price_min, price_max
from shipping
where shipping.price_min <= #form.subtotal#
and shipping.price_max >= #form.subtotal#
</cfquery>
If you continue to have problems, then verify that the database columns ship_cost, price_min and price_max have numeric datatypes. In any case, an even better query statement is:
<cfquery name="getInfo" datasource="#application.databasePRD#">
select ship_cost, price_min, price_max
from shipping
where shipping.price_min <= <cfqueryparam cfsqltype="cf_sql_numeric" value="#form.subtotal#">
and shipping.price_max >= <cfqueryparam cfsqltype="cf_sql_numeric" value="#form.subtotal#">
</cfquery>
North America
Europe, Middle East and Africa
Asia Pacific