Solved

Update a Price field with some calculations.

Posted on 2011-09-23
8
303 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:HainKurt
HainKurt 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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 51

Expert Comment

by:HainKurt
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:HainKurt
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:HainKurt
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

NFR key for Veeam Backup for Microsoft Office 365

Veeam is happy to provide a free NFR license (for 1 year, up to 10 users). This license allows for the non‑production use of Veeam Backup for Microsoft Office 365 in your home lab without any feature limitations.

Question has a verified solution.

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

Suggested Solutions

In this article I will describe the Backup & Restore 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.
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…
Via a live example, show how to setup several different housekeeping processes for a SQL Server.
Viewers will learn how the fundamental information of how to create a table.

808 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