Solved

Update a Price field with some calculations.

Posted on 2011-09-23
8
305 Views
Last Modified: 2012-05-12
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
   2. add 2.50

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

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

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
Comment
Question by:MikeMCSD
8 Comments
 
LVL 3

Accepted Solution

by:
jvejskrab earned 250 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 51

Assisted Solution

by:Huseyin KAHRAMAN
Huseyin KAHRAMAN earned 250 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
)

Open in new window

0
 
LVL 52

Expert Comment

by:_agx_
ID: 36589230
<ot> nice one @jvejskrab. very elegant </ot>
0
NEW Veeam Agent for Microsoft Windows

Backup and recover physical and cloud-based servers and workstations, as well as endpoint devices that belong to remote users. Avoid downtime and data loss quickly and easily for Windows-based physical or public cloud-based workloads!

 
LVL 51

Expert Comment

by:Huseyin KAHRAMAN
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
)

Open in new window

0
 
LVL 51

Expert Comment

by:Huseyin KAHRAMAN
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
)

Open in new window

0
 
LVL 51

Expert Comment

by:Huseyin KAHRAMAN
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
)

Open in new window

0
 
LVL 16

Author Comment

by:MikeMCSD
ID: 36589775
nicely done, thanks guys
0
 
LVL 3

Expert Comment

by:jvejskrab
ID: 36589834

Thanks @_agx_
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Table where row act as column 11 68
SQL Job Hung 17 35
SQL Pivot table 2 42
Trouble installing msi file with msiexe.exe 2 15
In this article I will describe the Detach & Attach method as one possible migration process and I will add the extra tasks needed for an upgrade when and where is applied so it will cover all.
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
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.
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question