...

View Full Version : Error In SQL Statement



victoria_1018
10-27-2003, 09:16 AM
Hi,
I am currently developing a shopping cart but had met some difficulties in inserting the delivery chagres.
The error prompt that there is error in the Selete Statement.
I had tried but could not spot the error.
Here is the statement statement

<%
WHILE NOT RS.EOF
weightTotal = weightTotal + ( RS( "product_weight" ) * RS( "cart_quantity" ) )
'Get Delivery Charges
sqlString1 = "SELECT user_country, DHL_Country, DHL_Weight, DHL_Price FROM users, DHLCharge" &_
"WHERE user_id=" & userID & " AND (user_country = DHL_Country " &_
"AND DHL_Weight LIKE %" & product_category & "%) "
SET RS = Con.Execute( sqlString1 )
deliveryCharge = RS( " DHL_Price" )
orderTotal = orderTotal + ( RS( "product_price" ) * RS( "cart_quantity" ) ) + deliveryCharge

%>

I had also attached the script in together with this page.
Thanks
Regards
victoria

glenngv
10-27-2003, 09:34 AM
To debug SQL statements easily, you need to response.write it.
Try it and you will see the syntax error.

HairyTeeth
10-27-2003, 10:04 AM
this part...


"SELECT user_country, DHL_Country, DHL_Weight, DHL_Price FROM users, DHLCharge" &_
"WHERE user_id=" & userID & " ..etc

should be like this:


"SELECT user_country, DHL_Country, DHL_Weight, DHL_Price FROM users, DHLCharge " &_
"WHERE user_id=" & userID & " ..etc

ie... a space between DHLCharge and the double quote. I set my sql statements out something like this (depending on the statement):


"SELECT user_country, DHL_Country, DHL_Weight, DHL_Price " &_
"FROM users, DHLCharge " &_
"WHERE " &_
"user_id=" & userID & " " &_
"AND " &_
"(user_country = DHL_Country " &_
"AND " &_
"DHL_Weight LIKE %" & product_category & "%) "

..which helps readability as well as the coding.

hth

whammy
10-29-2003, 02:58 AM
Also as GlennGV said, the absolute best way to debug any SQL statement is to response.write it. Then if the error isn't clear, you can paste it into Query Analyzer, and that may help. :)

victoria_1018
10-29-2003, 03:48 AM
Hi,
I am still working on it and I am afraid there is some other error in the page which cause the error.
Anyway thank You.
Vict



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum