?
Solved

SQL Round function - variable

Posted on 2011-03-09
2
Medium Priority
?
392 Views
Last Modified: 2012-05-11
I have a product table that has 3 fields;

ProductCode
Price (to 4 decimals)
DecimalIndicator (this is the number of decimal places that the price will be rounded to)

The decimal indicator will be a number between 0 and 4.

Example:
Price = 12.2412

If the decimal indicator is "2" then the price will display as 12.24
If the decimal indicator is "4" then the price will display as 12.2412

I will be using round(Price,X) to determine the price where X is the decimalindicator.

How can I amend my sql Round function to handle this variable decimal place?

Thank you and good night from Ireland!
0
Comment
Question by:Patrick O'Dea
[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
2 Comments
 
LVL 41

Accepted Solution

by:
Sharath earned 2000 total points
ID: 35089518
try like this.
select ProductCode,
       ROUND(Price,DecimalIndicator) as Price,
       DecimalIndicator
  from your_table

Open in new window

0
 

Author Closing Comment

by:Patrick O'Dea
ID: 35089562
Thanks - that was easy!
0

Featured Post

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

As tax season makes its return, so does the increase in cyber crime and tax refund phishing that comes with it
This article describes two methods for creating a combo box that can be used to add new items to the row source -- one for simple lookup tables, and one for a more complex row source where the new item needs data for several fields.
In Microsoft Access, learn how to “cascade” or have the displayed data of one combo control depend upon what’s entered in another. Base the dependent combo on a query for its row source: Add a reference to the first combo on the form as criteria i…
Using Microsoft Access, learn some simple rules for how to construct tables in a relational database. Split up all multi-value fields into single values: Split up fields that belong to other things into separate tables: Make sure that all record…
Suggested Courses

762 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