[10g] Way to find least value greater than a value?

I have a simple (I think) question ...
Part 1:
Is there a way to determine the least value, among a set of values, that is greater than 0?
A couple of examples:
Set of values:
{0,1,2,3}
Return value:
1
Set of values:
{0,5,10,20,100}
Return value:
5
Set of values:
{1,4,9,11}
Return value:
1Part 2:
Same thing, but greater than some given value, not necessary 0.
Set of values:
{0,1,2,3}
Parameter value:
2
Return value:
3
Set of values:
{0,5,10,20,100}
Parameter value:
2
Return value:
5
Set of values:
{1,4,9,11}
Parameter value:
2
Return value:
4In particular, I'm looking for an efficient way of doing this. I believe I can do it with a set of CASE statements, but it gets really complex the more values you are comparing.
My first thought was to use the LEAST function, but that doesn't allow me a way to use a parameter.
Any suggestions?

-- this section has been edited
And that's basically where I was heading. I was hoping there was a less complex way to do it... somehow replacing any zeros with an impossibly large number, without using case statements (something equivalent to the NVL function, but to replace any value with another), so that they'd never be less than anything, and then I could just use the LEAST function. The only way I can think of to do that though, would be to convert the numbers to strings, use REPLACE, and then convert them back to numbers, which doesn't seem less complex than the CASE statements, and most likely is worse performance-wise.
For example:
SELECT     ord_nbr
,     seq_nbr
,     time_spent /
     CASE     WHEN     comp_qty     <= plan_qty
          AND     comp_qty     <> 0
          THEN     comp_qty
          WHEN     comp_qty     > plan_qty
          THEN     LEAST     ( TO_NUMBER(REPLACE(TO_CHAR(ord_qty-scrap_qty),'0','999999999'))
                    , TO_NUMBER(REPLACE(TO_CHAR(plan_qty),'0','999999999'))
                    , TO_NUMBER(REPLACE(TO_CHAR(comp_qty),'0','999999999'))
          ELSE 1
     END     AS unit_time
FROM     ord_detail
;-- end of section edited (I posted before I had fully gone through the solution provided)
I checked the data, and though, theoretically all values could be zero, there are no instances where that happens. I think that, in the case all values were 0, I'd just want to use 1 instead.
Side note on the "big" problem behind this question....
My ultimate problem, (and if I end up needing help with that, I'll start a new post for it) is that the quantity data in our system has a fair amount of junk in it...values that can't be true. With this solution, I would assume that in any case where the quantity complete at a given step of a process is less than or equal to the quantity planned to be complete at that step, the value is good, which is not necessarily a correct assumption. Then, only in cases where something can't be true, like when quantity complete > the quantity planned, are when I would intervene with this solution to make a "best guess" at the correct value. There a few things related to this that I have to determine before I can figure out my next step.
We have another database (so we can keep things straight, I'll call the database I've been querying up til now DB1, and this other one, DB2) that has much more reliable quantity data and step data (sometimes it has steps that aren't in DB1) but its structure is complex, I'm rather unfamiliar with it, and it does not have time spent data. Additionally, some products have all their information in DB1, and none in DB2.
So my options are to:
1) ...try to learn the structure of the other database, find the data I need, and query both databases together, using this thread's solution to resolve any questionable data that does not exist in both systems, and skipping any steps that occur in DB2, but not DB1 (since they won't have any time data, which is ultimately what I'm after)
2) ...try to come up with a method to pre-"scrub" my data in DB1, based on some logical assumptions and looking at all steps in an order, so that I can then just query the scrubbed data...
3) ...use the solution from this thread, and assume that the bad data isn't enough to significantly impact my calculations...
What I wouldn't give for a single system with all good data!
Edited by: user11033437 on Nov 19, 2010 4:21 PM

Similar Messages

  • How to find login times greater than 24 hours from custom table.

    Hello Guru's,
    I am having trouble approaching how to construct a query that will find who has been logged in for more than 24 hours, this table is updated every few hours to show who's logged in and where- I am attempting to find out if someone has been logged in for more than 24 hours- if so, who and where. This is difficult for me because I need to compare each recorded for each user login and then see if the next entry is greater than 24 hours from the previous entry.
    A table holds the login times and locations as table position_hist:
    position_id,userid,upd_date.
    Something like;
    select position_id,userid,upd_date from position_hist where (select upd_date from position_hist where "the next entry for that user and that position is greater than 24 hours?????"
    I guess the easier way to look at it is for a given position_id who has been logged in for more than 24 hours in one go.
    Any advice would be brilliant :-)

    It's hard without knowing your Oracle version, or having any sample data to work with. Please post that in the future using \ tags and DDL/DML.
    Here is what I came up with as a guess:SQL> WITH POSITION_HIST AS
    2 (
    3 SELECT 1 AS POSITION_ID, 1 AS USER_ID, TRUNC(SYSDATE) AS UPD_DATE FROM DUAL UNION ALL
    4 SELECT 1 AS POSITION_ID, 1 AS USER_ID, TRUNC(SYSDATE)+1 AS UPD_DATE FROM DUAL UNION ALL
    5 SELECT 1 AS POSITION_ID, 1 AS USER_ID, TRUNC(SYSDATE)+2 AS UPD_DATE FROM DUAL UNION ALL
    6 SELECT 1 AS POSITION_ID, 1 AS USER_ID, TRUNC(SYSDATE)+4 AS UPD_DATE FROM DUAL UNION ALL
    7 SELECT 3 AS POSITION_ID, 2 AS USER_ID, TRUNC(SYSDATE) AS UPD_DATE FROM DUAL UNION ALL
    8 SELECT 3 AS POSITION_ID, 2 AS USER_ID, TRUNC(SYSDATE)+1 AS UPD_DATE FROM DUAL UNION ALL
    9 SELECT 3 AS POSITION_ID, 2 AS USER_ID, TRUNC(SYSDATE)+2 AS UPD_DATE FROM DUAL UNION ALL
    10 SELECT 4 AS POSITION_ID, 21 AS USER_ID, TRUNC(SYSDATE)+2 AS UPD_DATE FROM DUAL
    11 )
    12 SELECT POSITION_ID
    13 , USER_ID
    14 FROM
    15 (
    16 SELECT POSITION_ID
    17 , USER_ID
    18 , UPD_DATE - LAG(UPD_DATE) OVER (PARTITION BY USER_ID ORDER BY UPD_DATE) AS LOGGED_IN_TIME
    19 , ROW_NUMBER() OVER (PARTITION BY USER_ID ORDER BY UPD_DATE DESC) RN
    20 FROM POSITION_HIST
    21 )
    22 WHERE LOGGED_IN_TIME > 1 AND RN = 1
    23 /
    POSITION_ID USER_ID
    1 1                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Best way  for to choice number greater than 0.0001

    Hi
    I must put in where condition all number greater than zero, but the precion must to be in 4th place
    I tried in where condition
       trunc(abs(T$QUAN$O),4)>0.0001Is there some other way ?
    There are many columns that must compared (10 )
    Tia
    using
    Oracle9i Enterprise Edition Release 9.2.0.8.0 - 64bit Production
    PL/SQL Release 9.2.0.8.0 - Production
    CORE     9.2.0.8.0     Production
    TNS for IBM/AIX RISC System/6000: Version 9.2.0.8.0 - Production
    NLSRTL Version 9.2.0.8.0 - Production
    Edited by: muttleychess on Jan 11, 2012 7:01 PM

    I tried something like, but no work
    WITH X  AS(
      SELECT 1 COD, 0.001 VALOR FROM DUAL UNION ALL
      SELECT 2 COD, 0.0001 VALOR FROM DUAL UNION ALL
      SELECT 4 COD, 0.00001 VALOR FROM DUAL UNION ALL
      SELECT 5 COD, 0.000001 VALOR FROM DUAL UNION ALL
      SELECT 6 COD, -0.001 VALOR FROM DUAL UNION ALL
      SELECT 7 COD, -0.0001 VALOR FROM DUAL UNION ALL
      SELECT 8 COD, -0.00001 VALOR FROM DUAL UNION ALL
      SELECT 9 COD, -0.000001 VALOR FROM DUAL )
    SELECT X.*, TRUNC(ABS(VALOR),5) TRUNCADO, ABS(VALOR)*10000 MULTIPLY
    FROM X   
    WHERE TRUNC(ABS(VALOR),5)>0  should return only cod 1,2,4 and 5
    but
           COD      VALOR   TRUNCADO   MULTIPLY
             1      0,001      0,001         10
             2     0,0001     0,0001          1
             4       1E-5       1E-5        0,1
             6     -0,001      0,001         10
             7    -0,0001     0,0001          1
             8      -1E-5       1E-5        0,1What is wrong ?

  • HT202359 Is there a way to find the value of an unused itunes card without scratching the PIN security strip?

    I have an itunes gift card that I want to check the value so I know which card I am giving to whom. Is there a I can find the value without removing the security strip?

    Hi,
    sorry, i got no idea how to get the datatype of a variant, but there are properties "ActualSize" and "Type" of the ADO Field-Object. In case of an empty field the ActualSize is zero. Maybe you can use that. See VI below.
    best regards
    chris
    Best regards
    chris
    CL(A)Dly bending G-Force with LabVIEW
    famous last words: "oh my god, it is full of stars!"
    Attachments:
    DB_Test.vi ‏67 KB

  • Any way to find parameter value for a report?

    CS2008 SP3 - version 12.3.0.601
    Is there any way parameter value of a report can be found? The following code doesn't return parameter value but returns name.
    Fields existingReportParameters = null;
                            IDataDefinition dataDefinition = reportDocument.getDataDefinition();
                            existingReportParameters = dataDefinition.getParameterFields();
                            if (existingReportParameters != null) {
                                  for (int i = 0; i < existingReportParameters.size(); i++) {
                                        IField field = existingReportParameters.getField(i);
                                        if (field instanceof ParameterField) {
                                              ParameterField pa = (ParameterField)field;
                                              String paramName = pa.getName();
                                              //Values values = pa.getValues();
                                              //Object value = values.get(0);
                                              //System.out.println("*** repName Parameter - " + paramName + ":" + values);
                                              System.out.println("*** repName Parameter - " + paramName);
    Need to find a solution soon. Thanks in advance.

    Hello,
    Try searching, I have post code snippets on how to get values. I don't know for sure though if that code will work in CR 2008.
    Don

  • Query to find three times greater than the other records

    hi All,
    I am new to this forum, please help me out on this issue.
    There is a table named as regions which has following columns like name, region, population, area with the following sample records
    Region Name Population
    AAA AAAA 1000
    AAA BBBB 2000
    AAA CCCC 500
    BBB DDDD 900
    BBB EEEE 300
    I need to pick the record which has population more than three times that of any of their neighbours (in the same region). I need to get the region and name as the output. Please help me on how to write this query.

    with
       your_data as
       select 'AAA' as col1, 'AA' as col2, 7000   as col3 from dual union all
       select 'AAA' as col1, 'BB' as col2, 2000   as col3 from dual union all
       select 'AAA' as col1, 'CC' as col2, 500    as col3 from dual
    select *
    from
       select
          col1,
          col2,
          col3,
          case when col3 >= lag(col3) over (partition by col1 order by col3 asc) * 3
          then
             dense_rank() over (partition by col1 order by col3 desc)
          else
             0
          end as the_rank
       from
          your_data
    where
         the_rank = 1;
    COL CO               COL3           THE_RANK
    AAA AA               7000                  1
    1 row selected.
    Elapsed: 00:00:00.01
    TUBBY_TUBBZ?This code will return AT MOST one name for each region (assuming 1 or more qualify based on your description).
    Is that what you want?

  • Minimum in range greater than zero

    I'm trying to find the minimum number in a row but I want to find a number greater than zero as the minimum not the zeros .

    Badunit's remark that "Your numbers must all be >=0" led me to check all three suggestions against this possiblity. Here are the results for two data sets, one containing text, blank and negative values, the second containing only positve numbers, zero, and a blank cell.
    As you can see, my procedure includes both positive and negative values, and eliminates only the zeros from contention. If your data will include negative values, and you do NOT wish to include them, they may be easily stripped from the data when it is transfered the the Aux column, in the same manner as the zeroes have been.
    Stripping all values less than or equal to zero requies a minor edit of the formula in the AUX column:
    Original: =IF(B=0,"",B)
    Revised: =IF(B<=0,"",B)
    Jerry's formula requires that it be placed into a Footer row (or a Header row) IF it is to be placed on the Data table and to use the table name ("Data") as the first argument for INDEX. INDEX ignores Header and Footer rows in arguments specifying a whole column (or a whole table).
    As can be seen in column B, this formula will be thrown off (as BU has warned) by the inclusion of negative values. A revision similar to the one shown in my formula above will remove the requirement to not include negative values:
    Original: =SMALL(B,COUNTIF(B,0)+1)
    Revised: =SMALL(B,COUNTIF(B,"<=0")+1)
    As revised, the formula will return the smallest positive value in the data list.
    Badunit's formula will also show a warning triangle if there is an empty cell or a cell containing text in the data list. Annoying, but it does not affect the results. The warning is that "The formula refers to cells without numbers,"
    Regards,
    Barry

  • How to find a value into a data block

    There is a way to find a value into a data block, like finding
    one into a record group
    null

    Rafael Moreno (guest) wrote:
    : There is a way to find a value into a data block, like finding
    : one into a record group
    Try something like this:
    -- has to be in a when-button-pressed or key trigger
    go_block('x_block');
    first_record;
    r_found:=false;
    loop
    if :x_block.search_field:=search_value then
    r_found:=true;
    exit;
    end if;
    down;
    end loop;
    if r_found=false then
    first_record;
    message('Value '

  • Find a value in a boolean array

    Hey I have a boolean array with 500,000 values and I need to find the only one thats true. Is there an easy way to find this value?
    Thanks

    altenbach wrote:
    So far we assumed that you have a 1D array (you did not say!)
    (In the more general case, this idea would help too, but it does not seem to get a lot of love. Only 16 kudos )
    I'm sorry it's a 2D array.

  • Find spaces greater than particular width value

    Dear All,
    Requirement:
    In InDesign Scripting, is it possible to  straightly find spaces whose width is greater than particular value (e.g. 4 pts) to speedup a task.
    Currently we are finding most of the spaces and calculating their width as like below (i.e subtracting horizontal Offset value from end Horizontal Offset value) that is consuming more time.
    ====================================================================================
    Trying Script Code:
    myWidth=mySpace.endHorizontalOffset - mySpace.horizontalOffset;
    ====================================================================================
    Please advise.
    Thanks,
    Rajesh

    You can use a approach like this:
    1) grab myText.characters.everyItem().horizontalOffset. This will give you an array of every horizontal offset in your text.
    2) Grab myText.contents which will give you a string of all your text.
    3) Search your string for spaces and check the first array for the horizontalOffsets surrounding the space.
    This will allow you to do the check with only two DOM interactions and it should be very fast iterating over the string and array.

  • How do I disallow negative numbers in a selected group of cells (i.e. only allow values greater than or equal to zero)?

    I have a table of calculated values in Numbers, and I want to disallow negative numbers in the entire table. Any numbers that would be negative I would like changed to/displayed as zeroes, that way future calculations that may be based on this cell use the value of 0 for the calculation rather than the negative value. I have seen ways of doing this to single cells at a time, but I am interested in applying it to a large selection of cells.
    There is the Conditional Format option when you bring up the inspector, but I cannot get a custom rule to work for me. I select "Greater than or equal to" and I enter 0 in the box, but nothing changes. Can anyone help with this?
    Thanks

    A step toward simplifying the application of MAX to the issue, Jerry.
    This part, though:
    Now apply your long, animal-modeling, expressions to this new, interposing, table rather than the original.
    may still leave several references to be change from the original data table to the new one.
    One way to get around that is to use the Duplicate ("DATA-1) as the new table for raw data, and the Original (DATA) as the interposing table, using the formula =MAX(DATA-1::A2) as above, starting in DATA::A2.
    This way, the long expressions could continue to reference the original table (with its content now modified).
    ALTERNATE process:
    Find/Replace could also be used to speed the process of reassigning the modeling expressions to the duplicate table, as suggested by Jerry. But some cautions apply here.
    Find/Replace can be limited to Formulas only, but not to Some formulas only.
    Find/Replace can be limited to the Current Sheet only, but this can't be combined with Formulas only.
    More on this later, when I've had a chance to check some possibilities.
    Regards,
    Barry

  • Post park ivoice M8079 'Reversal value greater than value invoiced to date'

    I create a Service purchase order number is 8200000747 in our products system, and service entry sheet number is 1000026152, material document number is 5000306476.
    When I create a park invoice reference this Service PO, the system can not clear GR/IR account with that service entry sheet(1000026152). When we want to post this park invoice, system generate message M8079 'Reversal value greater than value invoiced to date'. But, this item never been verification invoice , I can find this not cleared  GR/IR data in MR11, this item not a multi account assignment , no foreign currency.
    What happened? How can I carry out the correct GR/IR account data in park invoice?

    Hello,
    Instead of reversing the invoice try posting the Credit Memo through MIRO .
    Regards
    Mahesh

  • Any way to create tablespace with name greater than 30 characters ?

    Is there any way to create tablespace greater than 30 characters on solaris 10 and Oracle 10g. Any way ? because i have no other option.

    desc dba_tablespaces
    So clearly the answer is NO.
    Tablespace names are invisible and irrelevant. Why the question?

  • Change "to equal" to "to be greater than" in Wait for Field to equal Value"

    In Sharepoint Designer 2010, in the workflow Action "Wait for Field to equal Value", I could change the "to equal" to "to be greater than". I can't find how to do this in SPD 2013.
    Can someone please help?
    Thank you!

    Hi
    PieterVanHeerden, is a big problem that gives us the change Microsoft . An option to mitigate this problem could be to use an additional workflow that runs whenever the item is updated . Workflow evaluate the condition that you need and when it is Ok, updates
    the value of a field used as flag called eg " Control_Hora_Inicio_Completo " with " true " value.
    In your current workflow you should modify the condition for the WorkflowF stops until the Control_Hora_Inicio_Completo field equal to " True " when it meets the Workflow continue and you're sure you have entered a value , whatever that is .
    I hope you can try and you work.
    Greetings from Argentina .
    Maxi
    Msorli

  • Export error: value of length column (38) greater than VARDATA column (36)

    Hello @,
    I am performing an export on HP-UX/Oracle of a R/3 Enterprise 1.10 system.
    I already use got the latest R3load binary. For pool table KAPOL I get
    this strange error and I couldn't find any further information about it:
    cat SAPPOOL.log
    (EXP) TABLE: "DEBI"
    (EXP) TABLE: "DVPOOL"
    (EXP) TABLE: "DVPOOLTEXT"
    (EXP) TABLE: "FINPL"
    (EXP) TABLE: "GLTP"
    (EXP) TABLE: "KALK"
    value of length column (38) greater than VARDATA column (36)
    (CNVPOOL) conversion failed for row 356 of table A004       VARKEY = 001V ZSP0003010TI060067A.01      00000000 
    (CNV) ERROR: data conversion failed.  rc = 2
    (DB) INFO: disconnected from DB
    /usr/sap/AVT/SYS/exe/run/R3load: job finished with 1 error(s)
    /usr/sap/AVT/SYS/exe/run/R3load: END OF LOG: 20110117114148
    SQL> desc kapol
    Name                                      Null?    Type
    TABNAME                                   NOT NULL VARCHAR2(30)
    VARKEY                                    NOT NULL VARCHAR2(195)
    DATALN                                    NOT NULL NUMBER(5)
    VARDATA                                            RAW(36)
    SQL> select length(vardata),count(*) from kapol group by length(vardata);
    LENGTH(VARDATA)   COUNT(*)
                 72     183681
    select dataln,count(*) from kapol  group by dataln;
        DATALN   COUNT(*)
        -32730          2
            36     183679
    Does this mean that one row in KAPOL has to be changed from within SAP?
    Or could it be an error/bug within R3load?
    Regards,
    Mark
    Edited by: Mark Foerster on Jan 17, 2011 12:46 PM

    Maybe this information is of any help:
    I opened a support call and was told by SAP support to change the
    two entries from -32730 to -32732. Don't ask me why...

Maybe you are looking for

  • I want to change my apple id, but I am told that the new email add is already linked to an account?

    I changed email addresses some time ago, and I thought that I had updated my Apple Account. When I tried to log in with the new email addy, I got a message that this emaill addy had not been set up as an account yet. So I cancelled that message, went

  • GSM Phone capabilities on Windows 8.1 Pro system

    Is it possible to have GSM phone (voice call) capability on a Windows 8.1 Pro system (e.g. a laptop/tablet with a GSM voice-capable mini PCI-E card such as Option's GTM671WFS)? And how would one go about getting it to work (assuming it is possible)?

  • Signed out by forum every half hour!

    If I've posted a topic and and following replies throught hte day - I am only kept signed in for a half hour at most! It is so frustrating to have to sign in 10x a day to use the forum. Can I adjust this setting anywhere? and no matter how many times

  • Reports: Need to modify the width of a field on Dashboard prompts

    Hello gurus, We have configured a report, and exposed it on the Dashboard. One of the fields in the Dashboard prompts called "Account Name" is unusually large. We assume this is because it is fetching the data directly from the DB, and the width is t

  • DTW of Opening Balances with Stock Taking Template

    Hello Gurus... I have the Stock Taking DTW Template with ItemCode, WarehouseCode, and Counted as the column names.  Straight from SAP.  I ran the DTW with actual Items (already connected to the appropriate warehouses).  The end result of the DTW is t