Solved

Need this SQL rewritten in C#

Posted on 2011-09-30
3
187 Views
Last Modified: 2012-05-12
I have this SQL :

UPDATE Nop_ProductVariant
SET Price =
CASE WHEN Price-floor(Price) >= 0.70 THEN floor(Price) + 0.95 ELSE
CASE WHEN Price-floor(Price) >= 0.50 THEN floor(Price) + 0.69 ELSE
CASE WHEN Price-floor(Price) >= 0.30 THEN floor(Price) + 0.49 ELSE
CASE WHEN Price-floor(Price) >= 0.01 THEN floor(Price) + 0.29  ELSE
CASE WHEN Price-floor(Price) = 0.00 THEN floor(Price) + 0.00
END END END END  END

It rounds the digits after the decimal point.

So if Price is "29.14", it would be "29.29", . . . "18.78" would be "18.99", etc.  

I now need this written in C#. How can I do this?  thanks

0
Comment
Question by:MikeMCSD
  • 2
3 Comments
 
LVL 9

Expert Comment

by:xav056
ID: 36892956
double price = 0;
if (price - System.Math.Floor(price) >= 0.7) {
      price = System.Math.Floor(price) + 0.95;
} else if (price - System.Math.Floor(price) >= 0.5) {
      price = System.Math.Floor(price) + 0.69;
} else if (price - System.Math.Floor(price) >= 0.3) {
      price = System.Math.Floor(price) + 0.49;
} else if (price - System.Math.Floor(price) >= 0.01) {
      price = System.Math.Floor(price) + 0.29;
} else if (price - System.Math.Floor(price) == 0.0) {
      price = System.Math.Floor(price) + 0.0;
}
0
 
LVL 9

Accepted Solution

by:
xav056 earned 500 total points
ID: 36892961
actually no need to declare price (take this out double price=0)
this should be it
if (price - System.Math.Floor(price) >= 0.7) {
      price = System.Math.Floor(price) + 0.95;
} else if (price - System.Math.Floor(price) >= 0.5) {
      price = System.Math.Floor(price) + 0.69;
} else if (price - System.Math.Floor(price) >= 0.3) {
      price = System.Math.Floor(price) + 0.49;
} else if (price - System.Math.Floor(price) >= 0.01) {
      price = System.Math.Floor(price) + 0.29;
} else if (price - System.Math.Floor(price) == 0.0) {
      price = System.Math.Floor(price) + 0.0;
}

Open in new window

0
 
LVL 16

Author Closing Comment

by:MikeMCSD
ID: 36893495
Thank you
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

911 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

18 Experts available now in Live!

Get 1:1 Help Now