Solved

SQL Round function - variable

Posted on 2011-03-09
2
377 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
Comment Utility
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
Comment Utility
Thanks - that was easy!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

QuickBooks® has a great invoice interface that we were happy with for a while but that changed in 2001 through no fault of Intuit®. Our industry's unit names are dictated by RUS: the Rural Utilities Services division of USDA. Contracts contain un…
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…
Learn how to number pages in an Access report over each group. Activate two pass printing by referencing the pages property: Add code to the Page Footers OnFormat event to capture the pages as there occur for each group. Use the pages property to …
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…

772 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

11 Experts available now in Live!

Get 1:1 Help Now