Solved

Update a Price field with some calculations.

Posted on 2011-09-23
8
307 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
[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
  • Learn & ask questions
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 53

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
MIM Survival Guide for Service Desk Managers

Major incidents can send mastered service desk processes into disorder. Systems and tools produce the data needed to resolve these incidents, but your challenge is getting that information to the right people fast. Check out the Survival Guide and begin bringing order to chaos.

 
LVL 53

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 53

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 53

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

Simplifying Server Workload Migrations

This use case outlines the migration challenges that organizations face and how the Acronis AnyData Engine supports physical-to-physical (P2P), physical-to-virtual (P2V), virtual to physical (V2P), and cross-virtual (V2V) migration scenarios to address these challenges.

Question has a verified solution.

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

Suggested Solutions

A Stored Procedure in Microsoft SQL Server is a powerful feature that it can be used to execute the Data Manipulation Language (DML) or Data Definition Language (DDL). Depending on business requirements, a single Stored Procedure can return differe…
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…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

751 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