Regarding MAX() function

Hi,
I am having table A. I have few records in the table A. Database version : 9.2
ID name deleted
2 XYZ N
3 ABD N
4 GJK N
5 GJK N
6 HGY N
7 YJG N
8 PIN N
9 BMF N
10 OLG N
I used the following query...
SELECT MAX(ID) FROM A WHERE DELETED='N';
It was worked fine until now....
Now i used the same query...
But the result is
MAX(ID)
9
Please help me... What is the reason?
I want the correct result...
Thanks in advance....                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

Kamran Agayev A. wrote:
Yes you can use TO_NUMBER inside MAX function and it will not give any error in the futureHave you tested it?
SQL> create table a (id,name,deleted)
  2  as
  3  select '2', 'XYZ', 'N' from dual union all
  4  select '3', 'ABD', 'N' from dual union all
  5  select '4', 'GJK', 'N' from dual union all
  6  select '5', 'GJK', 'N' from dual union all
  7  select '6', 'HGY', 'N' from dual union all
  8  select '7', 'YJG', 'N' from dual union all
  9  select '8', 'PIN', 'N' from dual union all
10  select '9', 'BMF', 'N' from dual union all
11  select '10', 'OLG', 'N' from dual
12  /
Tabel is aangemaakt.
SQL> select max(id)
  2    from a
  3   where deleted = 'N'
  4  /
MA
9
1 rij is geselecteerd.
SQL> select max(to_number(id))
  2    from a
  3   where deleted = 'N'
  4  /
                    MAX(TO_NUMBER(ID))
                                    10
1 rij is geselecteerd.
SQL> insert into a values ('2A', 'ABC', 'N')
  2  /
1 rij is aangemaakt.
SQL> select max(to_number(id))
  2    from a
  3   where deleted = 'N'
  4  /
select max(to_number(id))
FOUT in regel 1:
.ORA-01722: invalid numberRegards,
Rob.

Similar Messages

  • How to use MAX function in SSAS MDX Query

    I want to run this Query with MAX Condition on LAST_DATA_UPDATE Column .

    Hi Ashishsingh,
    According to your description, you want to know how to use MAX function in SQL Server Analysis Services MDX Query, right? In this case, please refer to the link below which describe the syntax and sample of MDX function.
    http://technet.microsoft.com/en-us/library/ms145601.aspx
    http://www.mdxpert.com/Functions/MDXFunction.aspx?f=64
    Hope this helps.
    Regards,
    Charlie Liao
    TechNet Community Support

  • Max() function in Data services

    Hi Experts,
         i'm using Data services (etl), and working on budget table(ms sql table),
    1. the table has a field [budget amount] and [version_no],
    2. before i extract the budget amount i need to know the highest version in [version_no] fields
    3. can any body help me on this? i tried to use the script:  ifthenelse(max(version-no),budget_amount, 0) but it retuns error when validation.
    please help me on this:
    thanks in advance
    Archie72

    Hi,
    Connect a Query transform say Query1 from the source table
    Inside Query1
    select MAX(version no) into the output. Do not select the other budget field into the output.
    Connect another Query transform say Query2 from the source table. Connect the output of Query1 also into Query2.
    Inside Query2:
    Join the source table and Query 1 in where
    Query1.version no = SourceTable.version no
    Select version no and budget into Query 2 output and connect it to target table.
    Assuming that the source table has only version number and budget. You might have to tweak and make use of Group By as required where you use the MAX() function. SourceTable mentioned in the where condition will be replaced with your exact source table name
    Regards,
    Suneer

  • Max function in select statemnt

    Hi,
       Can someone help me with what is wrong in the following query...How to use the max function
    in ABAP program select statement??
    Thanks..
    LOOP AT IT_ANLA_ANLZ INTO WRK_ANLA_ANLZ.
    SELECT KANSW
                FROM ANLC INTO TABLE IT_ANLC WHERE GJAHR IN ( SELECT MAX(GJAHR) FROM ANLC ) and ANLN1 = WRK_ANLA_ANLZ-ANLN1
                AND BUKRS = WRK_ANLA_ANLZ-BUKRS .
    APPEND IT_ANLC.
    ENDLOOP.

    Hi,
    You have write your select query once,
    and then loop on the internal table into
    which data will get populated for its display.
    SELECT KANSW
    FROM ANLC INTO TABLE IT_ANLC WHERE GJAHR IN
    ( SELECT MAX(GJAHR) FROM ANLC ) and ANLN1 = WRK_ANLA_ANLZ-ANLN1
    AND BUKRS = WRK_ANLA_ANLZ-BUKRS .
    Then loop at internal table:
    LOOP AT IT_ANLA_ANLZ INTO WRK_ANLA_ANLZ.
    write: / wrk_anla_anlz-fields.
    Endloop.
    Hope it helps
    Regards
    Mansi

  • Regarding max select statement.

    hi ,
        i m using max in select statement but its nt showing the o/p,cud u plz help me..thnx in advce.here i m giving the code....
    tables:s032.
    select-options:s_matnr for s032-matnr.
    data:begin of itab occurs 0,
         matnr like s032-matnr,
         letztzug like s032-letztzug,
         end of itab.
    select  matnr
    MAX( letztzug )
    into corresponding
    fields of
    table itab from s032 where matnr in s_matnr
    group by matnr
    order by
    matnr
    loop at itab.
    write:/ itab-matnr,itab-letztzug.
    endloop.

    select matnr
    MAX( letztzug )
    into
    table itab from s032 where matnr in s_matnr
    group by matnr
    order by
    matnr
    dont use corresponding fields of clause it is not matching the field name with max function.
    regards
    shiba dutta

  • Max function on a date field

    Hi,
    I would like to know if it's possible to do a Max function between two dates ?
    For instance I would like to do:
    Date Y = Max (created date + 4 days) and (Date X + 3 days)
    Thanks for your help,

    Thank you Dinesh for your fast reply.
    My request refer to a field management/WF.. So as you mentionned it's not possible in a standard way.
    But what kind of "other conditional statement" are you talking about?
    Regards,
    Vincent

  • Another MAX()  function question...

    Help was provided earlier for a question I had regarding use of the MAX function... This also pertains to that. I have two tables, employee and movie. I want to find the name of the employee who has entered the most amount of movies into our database. The query I have come up with so far (it's a little messy) is:
    SQL> select firstname, max(m) from (select firstname, count(enteredby) m from em
    ployee, movie where enteredby = id group by firstname) group by firstname;
    FIRSTNAME MAX(M)
    Peter 6
    Swanson 5
    Kevin 7
    Beverly 3
    So I have this table returned, now in this case I want to be able to select from this subquery the first name "Kevin", since he has entered in the most movies. In my head this seems so easy, "Grab the firstname of the person whose max(m) is the largest", but I am just having trouble getting this thought translated into a proper query!

    You can always do
    SELECT firstname
      FROM (SELECT firstname, RANK() OVER (ORDER BY max_m) rnk
              FROM (<<your query>>))
    WHERE rnk = 1Note that you'll need to alias the MAX(m) result first. You could also do
    SELECT firstname
      FROM (
    SELECT firstname, RANK() OVER( ORDER BY cnt) rnk
      FROM (SELECT firstname, COUNT(enteredby) cnt
              FROM employee e, movie m
            WHERE enteredby = id
            GROUP BY firstname)
    WHERE rnk = 1From a style standpoint, I would suggest that you get in the habit of aliasing your tables in your FROM clause and putting that alias on every column name to make it clear which table a particular column was selected from.
    I would also suggest that you come up with a column naming convention that caused the same value to be named the same (or similar) thing in different tables. Joining an ID column from one table to an ENTEREDBY, for example, would be a non-obvious bit of logic. It probably makes more sense to have an EMPLOYEE_ID and an ENTERED_EMPLOYEE_ID column.
    Justin

  • SUM and MAX Function ON PI

    HI Experts,
    AM Doing Idoc to File scenario,
    Target field   is SUPDAT     Formula     MAX( EDATU ) of all E1EDP20 segments of the current ORDERS05-E1EDK01-E1EDP01 segment.
    Target field is PLNQTY     Formula     SUM( WMENG - AMENG ) of all E1EDP20 segments of the current ORDERS05-E1EDK01-E1EDP01 segment, truncated, with leading zeroes, without decimals.
    For this i have to write UDF or can i use Graphical mapping here
    give me reply

    HI Arijit ,
    I Solved My SUM function .
    Regarding MAX(date) can you tell how to mapp this function in PI i want to calculate MAX(date) in orders05 IDOC.
    am waiting for ur reply
    thanks

  • Is max function will carry sort operation..?

    Hi friends,
    Is the max function will perform sort operation in temporary
    segments..? Please list the set of operations that will take
    place for the following Query (Apart from Syntax & Fetching the
    data).
    Ex:
    delete from tab1 p1
    where p1.rowid < (select max(p2.rowid)
         from tab1 p2 where
         p1.c1 = p2.c2);
    Regards,
    G. Rajakumar.

    you can get that information using explain plan command.
    DELETE STATEMENT
    DELETE TAB1
    FILTER
    TABLE ACCESS FULL TAB1
    SORT AGGREGATE TAB1
    TABLE ACCESS FULL TAB1

  • A query regarding synchronised functions, using shared object

    Hi all.
    I have this little query, regarding the functions that are synchronised, based on accessing the lock to the object, which is being used for synchronizing.
    Ok, I will clear myself with the following example :
    class First
    int a;
    static int b;
    public void func_one()
    synchronized((Integer) a)
    { // function logic
    } // End of func_one
    public void func_two()
    synchronized((Integer) b)
    { / function logic
    } // End of func_two
    public static void func_three()
    synchronized((Integer) a)
    { // function logic
    } // End of func_three, WHICH IS ACTUALLY NOT ALLOWED,
    // just written here for completeness.
    public static void func_four()
    synchronized((Integer) b)
    { / function logic
    } // End of func_four
    First obj1 = new First();
    First obj2 = new First();
    Note that the four functions are different on the following criteria :
    a) Whether the function is static or non-static.
    b) Whether the object on which synchronization is based is a static, or a non-static member of the class.
    Now, first my-thoughts; kindly correct me if I am wrong :
    a) In case 1, we have a non-static function, synchronized on a non-static object. Thus, effectively, there is no-synchronisation, since in case obj1 and obj2 happen to call the func_one at the same time, obj1 will obtain lock for obj1.a; and obj2 will obtain lock to obj2.a; and both can go inside the supposed-to-be-synchronized-function-but-actually-is-not merrily.
    Kindly correct me I am wrong anywhere in the above.
    b) In case 2, we have a non-static function, synchronized on a static object. Here, again if obj1, and obj2 happen to call the function at the same time, obj1 will try to obtain lock for obj1.a; while obj2 will try to obtain lock for obj2.a. However, since obj1.a and obj2.a are the same, thus we will indeed obtain sychronisation.
    Kindly correct me I am wrong anywhere in the above.
    c) In case 3, we have a static function , synchronized on a non-static object. However, Java does not allow functions of this type, so we may safely move forward.
    d) In case 4, we have a static function, synchronized on a static object.
    Here, again if obj1, and obj2 happen to call the function at the same time, obj1 will try to obtain lock for obj1.a; while obj2 will try to obtain lock for obj2.a. However, since obj1.a and obj2.a are the same, thus we will indeed obtain sychronisation. But we are only partly done for this case.
    First, Kindly correct me I am wrong anywhere in the above.
    Now, I have a query : what happens if the call is made in a classically static manner, i.e. using the statement "First.func_four;".
    Another query : so far we have been assuming that the only objects contending for the synchronized function are obj1, and obj2, in a single thread. Now, consider this, suppose we have the same reference obj1, in two threads, and the call "obj1.func_four;" happens to occur at the same time from each of these threads. Thus, we have obj1 rying to obtain lock for obj1.a; and again obj1 trying to obtain lock for obj1.a, which are the same locks. So, if obj1.a of the first thread obtains the lock, then it will enter the function no-doubt, but the call from the second thread will also succeed. Thus, effectively, our synchronisation is broken.
    Or am I being dumb ?
    Looking forward to replies..
    Ashutosh

    a) In case 1, we have a non-static function, synchronized on a non-static object. Thus, effectively, there is no-synchronisationThere is no synchronization between distinct First objects, but that's what you specified. Apart from the coding bug noted below, there would be synchronization between different threads using the same instance of First.
    b) In case 2, we have a non-static function, synchronized on a static object. Here, again if obj1, and obj2 happen to call the function at the same time, obj1 will try to obtain lock for obj1.a; while obj2 will try to obtain lock for obj2.a.obj1/2 don't call methods or try to obtain locks. The two different threads do that. And you mean First.b, not obj1.b and obj2.b, but see also below.
    d) In case 4, we have a static function, synchronized on a static object. Here, again if obj1, and obj2 happen to call the function at the same time, obj1 will try to obtain lock for obj1.a; while obj2 will try to obtain lock for obj2.a.Again, obj1/2 don't call methods or try to obtain locks. The two different threads do that. And again, you mean First.b. obj1.b and obj2.b are the same as First.b. Does that make it clearer?
    Now, I have a query : what happens if the call is made in a classically static manner, i.e. using the statement "First.func_four;".That's what happens in any case whether you write obj1.func_four(), obj2.func)four(), or First.func_four(). All these are identical when func_four(0 is static.
    Now, consider this, suppose we have the same reference obj1, in two threads, and the call "obj1.func_four;" happens to occur at the same time from each of these threads. Thus, we have obj1 rying to obtain lock for obj1.aNo we don't, we have a thread trying to obtain the lock on First.b.
    and again obj1 trying to obtain lock for obj1.aYou mean obj2 and First.b, but obj2 doesn't obtain the lock, the thread does.
    which are the same locks. So, if obj1.a of the first thread obtains the lock, then it will enter the function no-doubt, but the call from the second thread will also succeed.Of course it won't. Your reasoning here makes zero sense..Once First.b is locked it is locked. End of story.
    Thus, effectively, our synchronisation is broken.No it isn't. The second thread will wait on the same First.b object that the first thread has locked.
    However in any case you have a much bigger problem here. You're autoboxing your local 'int' variable to a possibly brand-new Integer object every call, so there may be no synchronization at all.
    You need:
    Object a = new Object();
    static Object b = new Object();

  • How to Avoid Errors in Max Function When Data Contains Blank Cells

    I have a column with duration values. However, it also contains some blank cells. These "blank cells" have formulas in them, but as the cells they reference too are blank the formula doesn't produce a result.>/p>
    I want to get the max value from this column. When I simply do =MAX(column-name) I get an error, presumably because some of the cells are blank. This table is going to be highly dynamic, so I don't want to limit the range of the MAX() function to only those cells with values.
    So does anyone know a solution for this, please? If I was some how able to create a formula which returned the range of cells with actual values, then I could use that in the MAX() function. Or, if I could somehow tell the MAX() function to ignore blank cells, but I'm not sure either of these are possible.
    Thanks,
    Nic

    I don't see a problem with "blank" (null string) cells mixed with duration cells.  MAX works fine with this mix of cells. But if the "blank" cells are numbers, not text, that gives an error.
    A formula always produces a result. A formula cannot result in a blank cell. The closest you can get to "blank" is a null string (the result of two quotes next to each other with nothing between them) . So the question is, what is the result that you are calling "blank"?

  • MAX function

    Hi Everyone,
    Am aware of the following flavors of MAX function
    1) choose MAX from the folders/fields list (selected items tab)
    2) create calculation using: MAX keep dense
    3) create calculation using: MAX analytic function
    questions, pls:
    ===========
    a) with MAX regular, MAX keep dense, MAX - analytic function
    is it necessary to sort it using tools/sort - choose fields to sort by?
    or does the data get sorted due to the ORDER BY clause in MAX used in a calculation
    b) how to understand the diff. bet. MAX keep dense and MAX - analytic function
    1) i understand that analytic functions are applied after detail row processing
    does MAX keep dense calculation happen during detail row processing?
    2) how did you know to advise when to use MAX keep dense, and when to use MAX - analytic function?
    tx for your ideas and assistance, sandra

    Hi,
    a) with MAX regular, MAX keep dense, MAX - analytic function is it necessary to sort it using tools/sort - choose fields to sort by? or does the data get sorted due to the ORDER BY clause in MAX used in a calculationIt is only necessary to use a sort if you want to have the rows returned in a specific order. The order by in the max calculation defines the maximum within the group or window. It may affect the order the rows are returned, but if it does this is not guaranteed and you should use a sort on the main query.
    b) how to understand the diff. bet. MAX keep dense and MAX - analytic function
    1) i understand that analytic functions are applied after detail row processing does MAX keep dense calculation happen during detail row processing?Yes
    2) how did you know to advise when to use MAX keep dense, and when to use MAX - analytic function?In general, if you want the result on a single row, so you have one row for each group then you should use the aggregate max. If you want to use the same max on all the rows in the window (defined by the partition) then use the analytic max.
    Rod West

  • Using max function in PL/SQL

    VERY URGENT...
    Am new to oracle...
    I've written a package that display gif images in form of histogram/bar chart. using html,
    I need to use max function to display values proportionately.
    please help. i need to complete this assignment by 2/9/00 by 10.00 am at the latest. I've half written a function but I don't know if there's a simpler way fo doing this. html enabled

    First of all Thanks to all gentlemen who replied ..many thanks ...
    Tried the ROW_NUMBER() option but still it is taking time...have given output for the query and tkprof results as well. Even when it doesn't fetch any record ( this is a valid cased because the input header id doesn't have any workflow request submitted & hence no entry in the wf_items table)..then also see the time it has taken.
    Looked at the RANK & DENSE_RANK options which were suggested..but it is still taking time..
    Any further suggestions or ideas as to how this could be resolved..
    SELECT 'Y', 'Y', ITEM_KEY
    FROM
    ( SELECT ITEM_KEY, ROW_NUMBER() OVER(ORDER BY BEGIN_DATE DESC) RN FROM
    WF_ITEMS WHERE ITEM_TYPE = 'xxxxzzzz' AND ROOT_ACTIVITY = 'START_REQUESTS'
    AND SUBSTR(ITEM_KEY,1,INSTR(ITEM_KEY,'-') - 1) = :B1
    ) T WHERE RN <= 1
    call count cpu elapsed disk query current rows
    Parse 0 0.00 0.00 0 0 0 0
    Execute 1 0.00 1.57 0 0 0 0
    Fetch 1 8700.00 544968.73 8180 8185 0 0
    total 2 8700.00 544970.30 8180 8185 0 0
    many thanks

  • Use of MAX function

    Hi,
    I am using parent-child hierarchy and in my reports I want to show Max(hierarchy_level). When I use the function MAX directly in the report it works fine in every way. But I want to have this kind of column in the BI Server presentation catalog so the user does not need to add MAX in Analysis/Answers (this is 11g). Normally this would imply a Max(hierarchy_level) as a logical function, but in the BI Server it is not allowed with MAX function in the logical function so it does not work.
    The hierarchy level is just a column from a dimension table and creating it as a fact column is not a very good solution. I also tried to solve this in many different ways, but only the MAX funtion in Analysis/Answers allways give the correct result. Used in combination with other dimensions etc. I want the exact same behaviour as I get when using MAX in analysis.
    Any good ideas to solve this? Is there another function in the BI Server that works the same way as MAX ?

    Very often, about a primary key, see for example our italian accounting application (our VAT invoices:fatture IVA) ), where the holes might be a problem.
    Yes Rosario, of course I know that, and that's why I said "in this scenario" : if primary key is the only purpose, I don't think holes could be a problem.
    Buona giornata anche a te.

  • Use of MAX function in Query Designer

    Dear all,
    i want to create a report that gives ONE line per period that holds the MAX of several lines per period. So NO addition of the KF but just one line item.
    I tried to use the MAX function and/or MAX drop-down boxes via properties on KF,
    but they all provide the wrong result (mostly the MAX after summaction of the KF).
    Any ideas ??
    Greetz,
    Herman

    Hi Herman
        Please check the KF infoobject property which might have been set to Summation.  You need to change the property of the KF to MAX if you wish to have MAX value. 
        Hope this might be helpful to you
    Thanks
    Kishore Kusupati

Maybe you are looking for

  • Credit data inconsistency

    Dear Experts ! Please help me in the below credit management scenario. User observed some inconsistent data in transaction -VKM1 with respect to the FD33 screen . I checked the data in RVKRED88 report and found that open order value of the sales orde

  • Multiple listings for one shared user

    Occassionally, a single user in my office will show up under the Shared Music heading in the iTunes source list multiple times! One coworker's shared library currently shows up 6 times, one after the other! Only the last listing actually connects to

  • Opening tabs in safari

    I have bookmarked 10 or 12 sites in a folder in my bookmarks collections. How can I open all these sites at once?

  • Photoshop Elements 11 on iMac 10.10.2. unresponsive.

    Application continues to go into unresponsive state. It hangs, eventually unhangs but as soon as I try to do anything with it, it goes into unresponsive state again. It has become completely unusable. I looked for answer on this forum but do not see

  • Flash timers, scores and transforms

    hi i have made a flash timer, displayTime, when it reaches 0 i want it to go to another scene but i dont know how to do that. i have made a score counter, points, if thescore reaches 18000 i want the game to go to anoher scene, but i dont know how to