Solved

Update a Price field with some calculations.

Posted on 2011-09-23
8
300 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
 
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
Free Gift Card with Acronis Backup Purchase!

Backup any data in any location: local and remote systems, physical and virtual servers, private and public clouds, Macs and PCs, tablets and mobile devices, & more! For limited time only, buy any Acronis backup products and get a FREE Amazon/Best Buy gift card worth up to $200!

 
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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

Suggested Solutions

If you have heard of RFC822 date formats, they can be quite a challenge in SQL Server. RFC822 is an Internet standard format for email message headers, including all dates within those headers. The RFC822 protocols are available in detail at:   ht…
How to leverage one TLS certificate to encrypt Microsoft SQL traffic and Remote Desktop Services, versus creating multiple tickets for the same server.
Viewers will learn how the fundamental information of how to create a table.
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…

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now