FRIHOST FORUMS SEARCH FAQ TOS BLOGS COMPETITIONS
You are invited to Log in or Register a free Frihost Account!


help, SQL Stored procedure - ASTM rouding rule





carlospro7
I don't have much SQL experience, this is my problem:

I have to write an SQL procedure that will apply ASTM rounding rules (or i guess also known as round-to-even method http://en.wikipedia.org/wiki/Rounding#Round-to-even_method. This page explains this method) to a column of floats (i.e. results) in a table and write the result of that application into another column of the table (i.e. ASTM_results). There is a column that specifies how many decimal places it should be rounded to (spec).

The starting table may look something like this
Code:

---------------------------------------
|  RESULTS  |  SPEC  |  ASTM_RESULTS  |
---------------------------------------
|   3.016   |    2   |      NULL      |
|   3.013   |    2   |      NULL      |
|   3.015   |    2   |      NULL      |
|   3.045   |    2   |      NULL      |
|  3.04501  |    2   |      NULL      |


After the ASTM rules have been applied (through the procedure) this is what the above table should look like
Code:

---------------------------------------
|  RESULTS  |  SPEC  |  ASTM_RESULTS  |
---------------------------------------
|   3.016   |    2   |      3.02      |
|   3.013   |    2   |      3.01      |
|   3.015   |    2   |      3.02      |
|   3.045   |    2   |      3.04      |
|  3.04501  |    2   |      3.05      |


It should apply it to every row and add the rounded number to the ASTM_RESULTS field in its corresponding row. I hope that makes sense.

Like I said I don't know much SQL, but I have to apply this to a table in SQL. If anyone can help it would be much appreciated.
sonam
I don't know so much about SQL but it is easy to calculate this with PHP. If you can aplly php code then you can use round() function:
http://www.php.net/manual/en/function.round.php

Example:
Code:
echo round(1.95583, 2);  // 1.96 Number 2 is spec in your table


Sonam
carlospro7
I got a solution to this problem in a different page. Here is the link:

http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=105644

This problem can be considered solved.
Related topics
Help: SQL error after uploading new files(thread updated)
SQL - need help
.sql problem
Ranking system, how to do it without use too much resource
The Middle East Conflict
Access DataBase using visual basic6
mysql insert into multiple tables at once?
Help SQL Sort
Strange SQL cursor problem. Pls do not ignore if can help.
Mount & blade, what is it?
Morality of deleting an 'intelligent' computer program
SELECT in Procedure Causes Error #1312 (ER_SP_BADSELECT)
[TuT]JOOMLA Installation Guide (Less Easy Way)
oracle sql Alter table from a triggered package procedure
Reply to topic    Frihost Forum Index -> Scripting -> Others

FRIHOST HOME | FAQ | TOS | ABOUT US | CONTACT US | SITE MAP
© 2005-2011 Frihost, forums powered by phpBB.