Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# Update a Price field with some calculations.

Posted on 2011-09-23
Medium Priority
310 Views
I need to Update the Price field with this critera :

IF OldPrice < 5.00
Price =
1. add the difference of  : (5.00 - (OldPrice - ProductCost)) to OldPrice

IF OldPrice >= 5.00 AND <= 10.00
Price =
1. add the difference of  : (8.00 - (OldPrice - ProductCost)) to OldPrice

IF OldPrice >= 10.00 AND <= 20.00
Price =
1. add the difference of  : (12.00 - (OldPrice - ProductCost)) to OldPrice

Should produce this example data :

The field : OldPrice ProductCost
data :   4.95     3.76

1. (5.00 - (4.95 - 3.76)) = 3.81         Price =  4.95 + 3.81 = 8.76
2. Price =   8.76 + 22.50 = 11.26

UPDATE Nop_ProductVariant
SET Price = OldPrice ProductCost  ??

What is the best way to code this? thanks
0
Question by:MikeMCSD
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 3

Accepted Solution

jvejskrab earned 1000 total points
ID: 36589174

UPDATE Nop_ProductVariant
SET Price =  OldPrice + (CASE
WHEN OldPrice < 5 THEN  5
WHEN OldPrice BETWEEN 5 AND 10 THEN 8
ELSE 12
END
- (OldPrice - ProductCost)) + 2.5
0

LVL 59

Assisted Solution

HainKurt earned 1000 total points
ID: 36589227
here if above does not work...
``````UPDATE Nop_ProductVariant
SET Price = OldPrice + 2.5 + (
CASE
WHEN OldPrice < 5 THEN 5.00 - (OldPrice - ProductCost)
WHEN OldPrice BETWEEN 5 AND 10 THEN 8.00 - (OldPrice - ProductCost)
WHEN OldPrice BETWEEN 10 AND 20 THEN 12.00 - (OldPrice - ProductCost)
END
)
``````
0

LVL 52

Expert Comment

ID: 36589230
<ot> nice one @jvejskrab. very elegant </ot>
0

LVL 59

Expert Comment

ID: 36589235
which is equal to

``````UPDATE Nop_ProductVariant
SET Price = 2.5 + (
CASE
WHEN OldPrice < 5 THEN 5.00 + ProductCost
WHEN OldPrice BETWEEN 5 AND 10 THEN 8.00 + ProductCost
WHEN OldPrice BETWEEN 10 AND 20 THEN 12.00 + ProductCost
END
)
``````
0

LVL 59

Expert Comment

ID: 36589242
which is
``````UPDATE Nop_ProductVariant
SET Price = (
CASE
WHEN OldPrice < 5 THEN 7.50 + ProductCost
WHEN OldPrice BETWEEN 5 AND 10 THEN 10.50 + ProductCost
WHEN OldPrice BETWEEN 10 AND 20 THEN 14.50 + ProductCost
END
)
``````
0

LVL 59

Expert Comment

ID: 36589246
which is
``````UPDATE Nop_ProductVariant
SET Price = ProductCost + (
CASE
WHEN OldPrice < 5 THEN 7.50
WHEN OldPrice BETWEEN 5 AND 10 THEN 10.50
WHEN OldPrice BETWEEN 10 AND 20 THEN 14.50
END
)
``````
0

LVL 16

Author Comment

ID: 36589775
nicely done, thanks guys
0

LVL 3

Expert Comment

ID: 36589834

Thanks @_agx_
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Ever needed a SQL 2008 Database replicated/mirrored/log shipped on another server but you can't take the downtime inflicted by initial snapshot or disconnect while T-logs are restored or mirror applied? You can use SQL Server Initialize from Backupâ€¦
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that witâ€¦
This video shows, step by step, how to configure Oracle Heterogeneous Services via the Generic Gateway Agent in order to make a connection from an Oracle session and access a remote SQL Server database table.
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.
###### Suggested Courses
Course of the Month11 days, 19 hours left to enroll