Solved

SQL Round function - variable

Posted on 2011-03-09
2
383 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
2 Comments
 
LVL 40

Accepted Solution

by:
Sharath earned 500 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

Migrating Your Company's PCs

To keep pace with competitors, businesses must keep employees productive, and that means providing them with the latest technology. This document provides the tips and tricks you need to help you migrate an outdated PC fleet to new desktops, laptops, and tablets.

Question has a verified solution.

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

In the previous article, Using a Critera Form to Filter Records (http://www.experts-exchange.com/A_6069.html), the form was basically a data container storing user input, which queries and other database objects could read. The form had to remain op…
I originally created this report in Crystal Reports 2008 where there is an option to underlay sections. I initially came across the problem in Access Reports where I was unable to run my border lines down through the entire page as I was using the P…
Basics of query design. Shows you how to construct a simple query by adding tables, perform joins, defining output columns, perform sorting, and apply criteria.
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…

791 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