SQL for rounding to the nearest value
Hi All,
My Oracle DB version is 10g Release2 and also 11gR1
I have data like below, I need to write a SQL for the below requirement.
ID RANGE_LOW RANGE_HIGH
1 50 55
2 55 60
3 60 63
4 63 77
5 77 84 The requirement is like I need to check a value between the above range low and high then round it to the nearest value.
Say, for example if I have 68 then the value is rounded to 63 else if 74 then 77 else if its in the middle of two values (70) then rounded to the highest value, here its 77.
Please advice.
Ashu_Neo wrote:
hi Purvesh,
I think , you didn't check it properly with requirement of posting. Your query needs to be changed a bit. Please verify againYes, I probably missed or overlooked the last line.
Here is the updated solution then:
with data as
select 1 id, 50 low, 55 high from dual union all
select 2, 55, 60 from dual union all
select 3, 60, 63 from dual union all
select 4, 63, 77 from dual union all
select 5, 77, 84 from dual
chk_val as
select &val val from dual
select id, low, high,
val input_value,
case
when val < (low + high)/2
then low
else
high
end round_value
from data, chk_val
where val between low and high;
ID LOW HIGH INPUT_VALUE ROUND_VALUE
4 63 77 70 77
Similar Messages
-
Rounding off to nearest value with formatNumber
Can I use the formatNumber tag to round my numeric value to the nearest value?
Like if it's 15.7 I would like to display 16
And if it's 15.2, I would like to display 15
I could successfully truncate by giving a patteren but Im not sure if I can round it off.
Regards,
LeenaYes you can - the following works on JSTL 1.1 / Tomcat 5.5 :
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<html>
<head><title></title></head>
<body>
Test Auto Rounding of 16.8 :
<fmt:formatNumber value="16.88" pattern="##"/>
<br/><br/>
Test Auto Rounding of 16.2 :
<fmt:formatNumber value="16.22" pattern="##"/>
</body>
</html>Message was edited by:
appy77 -
Problem in Routine after rounding off the condition value
Dear all,
I have attached the routine for rounding off value for condition value for T.Code va02. Routine is working fine but the problem is after the execution of routine it goes in some standard program LV61AA55 where again the rounded value gets changed . Maximum points will be allocated ..
Thanks anr RegardsFORM FRM_KONDI_WERT_925.
*{ INSERT D01K911062 2
data : wa_xkomv like xkomv,
v_kwert like xkomv-kwert,
W_INDEX TYPE SY-TABIX.
read table xkomv into wa_xkomv with key kschl = 'JIN6'.
W_INDEX = SY-TABIX.
v_kwert = 1 * wa_xkomv-kwert / 100.
V_KWERT = WA_XKOMV-KWERT.
read table xkomv with key kschl = 'JHSC'.
CALL FUNCTION 'J_1I6_ROUND_TO_NEAREST_AMT'
EXPORTING
I_AMOUNT = v_kwert
I_AMOUNT1 =
I_AMOUNT2 =
I_AMOUNT3 =
I_AMOUNT4 =
I_AMOUNT5 =
I_EXADDTAX1_AMOUNT =
I_EXADDTAX2_AMOUNT =
I_EXADDTAX3_AMOUNT =
IMPORTING
E_AMOUNT = v_kwert
E_AMOUNT1 =
E_AMOUNT2 =
E_AMOUNT3 =
E_AMOUNT4 =
E_AMOUNT5 =
E_EXADDTAX1_AMOUNT =
E_EXADDTAX2_AMOUNT =
E_EXADDTAX3_AMOUNT =
xkomv-kwert = v_kwert.
xkwert = v_kwert.
modify xkomv INDEX W_INDEX transporting kwert.
*} INSERT
ENDFORM. -
How to use SQL import to set the attribute value based on another?
Hello all,
I want to set an attribute of a dimension based on another attribute (if matches). Let's say I have a dimension PRODUCT. And I have defined two user defined attributes MANAGER and ISVISIBLE.
Now within a PERMIT_READ program I want to set the ISIVISIBLE to true where the MANAGER Value is selected from a table.
Something like
<define a cursor c1 to select all the Manager values>
sql import c1 into -
:MATCHSKIPERR PRODUCT_MANAGER then <PRODUCT_ISVISIBLE (PRODUCT MANAGER) = true>
<etc>
Obviously the above is not correct. But I am stuck as to how this can be done? Can some one on this forum please help me with correct syntax/ approach please?
Thanks a lot.
Pxsheth
This statement assigns true to the isvisible attribute for every gc_dim_bu dimension (selected as part of cursor c1).
SO FAR SO GOOD.. NOW -
If I want to change the above so that the attribute value gets assigned based on another attribute for the dimension (say a flag). i.e.
Set the isvisible to true where attribute flag has a certain value. How do I code this in OLAP DML?There are a number of ways to do this. If you want to use an attribute that has been defined within AWM as an attribute of Product then simply using the mapping tool to populate the attribute as part of the normal dimension load procedure.
Alternatively you could create an attribute at the DML level, and assuming you are not using surrogate keys, you can then define a cursor to read the relational table to populate your attribute. Something like this:
sql declare MKT_BASKET cursor for -
select PRODUCT_ID, PROD_MGR , PROD_VISIBLE -
from PRODUCT_DIM
if SQLCODE ne 0
then goto ERROR
sql open MY_CURSOR
sql fetch MY-CURSOR loop into :append PRODUCT, :PRODUCT_MANAGER, :PRODUCT_ISVISIBLE
sql close MY_CURSOR
sql cleanup
update
commit
If you want to create a complex PERMIT function using OLAP DML then personally I would create a formula and assign a program of type BOOLEAN and have the program return a YES or NO depending on the outcome of your test. Then your PERMIT_READ still references a dimension object. For example:
DEFINE PROD.ISVISIBLE BOOLEAN FORMULA <PRODUCT>
EQ PRG.ISVISIBLE(PRODUCT)
DEFINE PRG.ISVISBLE PROGRAM BOOLEAN
The program will then return Yes or No depending on the processing you need to do.
Hope this helps
Keith Laker
Data Warehouse Solution Architect
Oracle EMEA Consulting
BI Blog: http://oraclebi.blogspot.com/
DM Blog: http://oracledmt.blogspot.com/
BI on Oracle: http://www.oracle.com/bi/
BI on OTN: http://www.oracle.com/technology/products/bi/
BI Samples: http://www.oracle.com/technology/products/bi/samples/ -
Rounding to the nearest thousand
hi
does anybody know how to ceil and floor an integer to the nearest thousand?
thanks in advance?hi friend,
try this code, it may help you.....
public class NT {
/** Creates a new instance of NT */
public NT() {
public int roundByThousands(int val)
int retval=0;
for(int i=0;i<val;i=i+1000)
int k=val-i;
if(k<1000)
if(k<=500)
retval=val-k;
else
retval=(1000-k)+val;
return retval;
public static void main(String args[])
NT nt=new NT();
System.out.println(nt.roundByThousands(11502));
} -
UIDatePicker doesn't snap or animate to the nearest value
I use a UIDatePicker for a users Date Input, my Date Picker is inside a UIView, and on all OS Revisions and Devices (that I have tested) except "iPad 1" iOS 5.x -- everything works great. On iPad 1 with iOS 5.x when you scroll a wheel it stops inbetween months/days/years and does not animate to the nearest date. It also therefor does not set the date (it appears the date is only set when the exact date is reached [or close to it] and not if it stops inbetween.
I have read that CCDirector causes issues with the UIDatePicker on iPad 1 iOS 5.x, but I do not use cocos2d, however, it points out that there may be an issue somewhere where I am doing something similar.
Any thoughts?
--DaveI have this problem too (ios 5.1.1, ipad 1). You find solution?
-
can we generate one report tab which filters
with each prompt value selected in bobj 4.0 webi report.Hi Shrinidhi ,
It can be achievable with static tabs created for each LOV .But this is not recommended because , object values can change dynamically .
It is good idea to use section on prompt object in the report .With sections great feature available is in larger report it’s easy to navigate using map. It displays the section tree.You can select the particular LOV to navigate. -
Finding the nearest value.
Hi Gurus,
I have an internal table with values country code and current price and using a selection screen i get a price, now i need to pick a value from the table which is nearest to the one in the screen. How do i achieve this logic? All help regarding this is very much appreciated.
Thanks,give 10 as input and execute this program
parameters:valin type p.
data:begin of itab occurs 0,
val type p decimals 2,
end of itab.
itab-val = '10.13'.
append itab.
itab-val = '14.13'.
append itab.
itab-val = '9.13'.
append itab.
itab-val = '4.13'.
append itab.
itab-val = '22.13'.
append itab.
sort itab descending.
loop at itab where val <= valin.
write itab-val.
exit.
endloop. -
How to exit from SQL*Plus based on the return value of a SQL select stment?
Hi
I have a SQL script executed from SQL*Plus. I would like to know if SQL*Plus
supports any kind of branching or exiting from script execution based on a
returned value of a SQL select statement. I am on 9i.
Regards,
Tamas Szecsyin sqlplus, you have whenever
ex:
whenever sqlerror exit failure
insert into ...
-- if this fails, then you will be out
insert into ...
-- if this fails, then you will be out
whenever sqlerror continue
insert into ...
-- if this fails, this continues
insert into ...and you have PL/SQL
declare x number;
begin
select count(*) into x from emp;
if (x=14) then null; end if;
end;
/note that you can mix those in some case
-- exit if there is no row in emp
whenever sqlerror exit 1
var dummy number
exec select count(*) into :dummy from emp having count(*)!=0 -
Condition type for rounding-off
Dear all,
Is there any pricing condition for rounding off the PO values,
For example if the total PO Value is comes Rs 5990/- & i want to make it Rs 6000/-.In the same way i want to deduct some amount to make the rounding off like total PO Value comes as Rs 10015/-, & i want to make it Rs 10000/- by applying the same condition.
Or Can i create a new condition type for this type of scenerios.
Quick reply will be highly appreciated.
Thanks & Regards
Prasant sekharin condition type u have a filed for rounding off
so use the relveant option from f4 help in that field and u can round of the value as u want to be
go to tcode m/06
and select ur conditoin type and click on the detail button and do the relevant settings -
Formulae - rounding down to the nearest five
I am new to JAVA programming and not (yet) a brilliant mathematician. Can anybody tell me an algebra formula for rounding down to the nearest 5 (in 100)? Thanks in advance [email protected]
Your question is not very clear.
Still I think this would help
//begin
int remainder = number % 5 ;
//We get the remainder
number = number - remainder;
//Trim down to the lower value
if (remainder >= 3){
number = number + 5 ;
//If the remainder is 3 or more we should round to the higher value
//End of block
Hope this helps
Shubhrajit -
User exit for rounding off result value
Hi Gurus,
Is there any user exit available or std. functionality by which we can round off the result value. My client wants if the value is 192.5 or 191.8 then this value should be rounded off to 195. That means rounding in multiples 0f 5. Is there any exit available?
Regards
AmitIf in QM just specify the correct number of decimals for the characteristic, in your case 0. In config under plant settings you can set up the results recording settings to allow you to record one additional decimal then specified by the characteristic. The result is rounded to 0 decimals when displayed.
FYI - there should be no reason to have to use user exits to round off decimals in QM.
Craig
I didn't read the initial posting correctly. To round the whole number portion by 5 you will have to provide that logic yourself via the user exits already posted.
Craig
Edited by: Craig Snyder on Jan 13, 2010 2:56 PM -
How to round numbers to the nearest .25
I would like to enter a number in one field and have it rounded to the nearest .25 in another column - (whether that's rounding up or down)
Example:
Actual Size
Adjusted Size
7.21435
7.25
Any help would be appreciated.
Thanks!Hi c,
The ROUND function limits the precision choices to powers of 10, so we need to work within that limitation:
Multiply by four, round to the nearer whole number, divide by four.
Formula in column B: =ROUND(A*4,0)/4
All cells in B are formatted as Number, with decimal places set to 2.
Regards,
Barry -
Rounding Time to nearest 30 minutes
Good day,
I'm looking for a way to round the time portion of a date value. My query needs to return the time of day, rounded to the nearest 30 minutes - top of the hour or bottom of the hour.
If sysdate is: 12/28/2009 11:08:19 AM
I need to see: 12/28/2009 11:00:00 AM
If sysdate returns: 12/28/2009 11:18:19 AM
I need to see: 12/28/2009 11:30:00 AM
Any help is appreciated.
Regards,
Gary F.Aketi Jyuuzou wrote:
I like case expression B-)Me too, but I like then simple B-) :
with dates as ( -- generating sample data
select to_date('12/28/2009 11:08:19', 'mm/dd/yyyy hh:mi:ss') dt from dual union all
select to_date('12/28/2009 11:18:19', 'mm/dd/yyyy hh:mi:ss') dt from dual union all
select to_date('12/28/2009 11:38:19', 'mm/dd/yyyy hh:mi:ss') dt from dual union all
select to_date('12/28/2009 11:48:19', 'mm/dd/yyyy hh:mi:ss') from dual)
select dt,
case when to_char(dt,'mi') >= '45'
then trunc(dt,'hh') + interVal '60' minute
when to_char(dt,'mi') >= '15'
then trunc(dt,'hh') + interVal '30' minute
else trunc(dt,'hh')
end as new
from dates
DT NEW
2009-12-28 11:08:19 2009-12-28 11:00:00
2009-12-28 11:18:19 2009-12-28 11:30:00
2009-12-28 11:38:19 2009-12-28 11:30:00
2009-12-28 11:48:19 2009-12-28 12:00:00
SQL> SY. -
Rounding minutes to nearest five.
Hi,
I have tried the various methods suggested on other forum messages but to no avail.
I have a GUI that acts as the client for a reminder system i am making for some coursework.
It contains a combo box with values for the user to select a time from, however the time is not displayed in the format i would like it to be.
I would like the current time from the instance of calendar i have created to be rounded to the nearest five up.
The code i have for the combo box at the moment is:
cal.set(cal.MINUTE, (int)Math.round((double)cal.MINUTE));
n=0;
int z = 0;
while(z<288)
cal.add( cal.MINUTE, n);
s = DateFormat.getTimeInstance(DateFormat.SHORT).format(cal.getTime());
time_cb.addItem(s);
n=5;
z++;
This code always sets the first value of the combo box to 10 minutes past the hour and increments it by five from there. This happened with all the other methods i tried from the other forums also.
I would like it to round to the nearest five the current time and increment by five from this time.
Thanks for your time and help.Hi,
I have tried the various methods suggested on other
forum messages but to no avail.
I have a GUI that acts as the client for a reminder
system i am making for some coursework.
It contains a combo box with values for the user to
select a time from, however the time is not displayed
in the format i would like it to be.
I would like the current time from the instance of
calendar i have created to be rounded to the nearest
five up.
The code i have for the combo box at the moment is:
Your first line is wrong. Your setting the calendar minutes field to
some random value, cal.MINUTE, which has nothing to do with the current minute. You need to do
Calendar c = new GregorianCalendar()
which automatically sets the current minute
cal.set(cal.MINUTE,
(int)Math.round((double)cal.MINUTE));
n=0;
int z = 0;
while(z<288)
cal.add( cal.MINUTE, n);
s =
=
DateFormat.getTimeInstance(DateFormat.SHORT).format(ca
.getTime());
time_cb.addItem(s);
n=5;
z++;
This code always sets the first value of the combo box
to 10 minutes past the hour and increments it by five
from there. This happened with all the other methods i
tried from the other forums also.
I would like it to round to the nearest five the
current time and increment by five from this time.
Thanks for your time and help.
Maybe you are looking for
-
Hi Experts I have small problem and doubt If i login to global zone ... "zlogin -C -e @ testzone" how to logout from global zone...... testzone# when i press exit button it is comeing to zone login prompt zone1 console login: @ ( from Zone login prom
-
Report for equipment with Asset number
Hi I want report where i can get equipment number with asset number. I hecked information system. But id din't got
-
hi, i have created below thread in SAP NetWeaver Administrator, but no response, thought i posted it to wrong category. https://forums.sdn.sap.com/click.jspa?searchID=15443307&messageID=6020795 i re-post the same question here, hope there is someone
-
Order Status says "Page Currently Not Available"
It has been working for me ever since Thursday. It hasn't said anything but We Received Your Order and We Are Processing it or whatever, but at least it came up. Is it down for everyone else?
-
FLV player not working on website
Well recently I've been making a website, I'm recently new to Dreamweaver, and previously I had input two FLV's in two different AP div boxes. They both worked fine, but after creating a few more pages, I can only come back to see it broken. Instead