shopping cart

J

John Smith

Hi,

I'm trying to work out the postage rate for products in a shopping cart.
Predictably there is no formula for working out the postage rate (ie. 0.20 *
weight). The problem i'm having is with the statement for working this out

There are different 'bands' for the weight (i.e. between 150g and 200g the
price is 0.50). What's the best way to write a statement for this ? I have
tried different ways of writing an If statement but they all end up in
chaos.

John
 
A

Aaron Bertrand - MVP

Use a database table. Assuming SQL Server:



CREATE TABLE postageRates
(
weightlowerbound INT,
weightupperbound INT,
rate DECIMAL(19,2)
)

INSERT postageRates VALUES(0, 149, 0.25)
INSERT postageRates VALUES(150, 200, 0.50)
INSERT postageRates VALUES(201, 500, 0.85)
-- ...

DECLARE @weight INT
SET @weight = 172
SELECT rate FROM postageRates
WHERE @weight
BETWEEN weightlowerbound AND weightupperbound

DROP TABLE postageRates



You could also do this within an array in ASP...
 
J

John Smith

works great, thanks !


Aaron Bertrand - MVP said:
Use a database table. Assuming SQL Server:



CREATE TABLE postageRates
(
weightlowerbound INT,
weightupperbound INT,
rate DECIMAL(19,2)
)

INSERT postageRates VALUES(0, 149, 0.25)
INSERT postageRates VALUES(150, 200, 0.50)
INSERT postageRates VALUES(201, 500, 0.85)
-- ...

DECLARE @weight INT
SET @weight = 172
SELECT rate FROM postageRates
WHERE @weight
BETWEEN weightlowerbound AND weightupperbound

DROP TABLE postageRates



You could also do this within an array in ASP...



0.20
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top