Solved

SQL Round function - variable

Posted on 2011-03-09
2
389 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 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

It’s the first day of March, the weather is starting to warm up and the excitement of the upcoming St. Patrick’s Day holiday can be felt throughout the world.
In earlier versions of Windows (XP and before), you could drag a database to the taskbar, where it would appear as a taskbar icon to open that database.  This article shows how to recreate this functionality in Windows 7 through 10.
In Microsoft Access, learn different ways of passing a string value within a string argument. Also learn what a “Type Mis-match” error is about.
With Microsoft Access, learn how to specify relationships between tables and set various options on the relationship. Add the tables: Create the relationship: Decide if you’re going to set referential integrity: Decide if you want cascade upda…

733 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