Combining max, average and group by

Hi!
I have a simple table called Rates consisting of RateTime (datetime), Ask (decimal) and OrderSymbol (char)
I'm trying to create a select statement that will give me one row for each unique value in OrderSymbol consisting of columns for "CurrentAsk", "AVG(Ask)", and "OrderSymbol".
CurrentAsk has to be the latest one registered, so MAX(RateTime) for each OrderSymbol.
Is this possible?
TIA!
Dennis

Sure, using OVER() clause added in SQL Server 2005, e.g.
;with cte as (select RateTime, Ask,
AVG(ask) OVER (partition by OrderSymbol) as AverageAsk,
OrderSymbol, ROW_NUMBER() OVER (partition by OrderSymbol ORDER BY RateTime DESC) as RN
FROM dbo.Rates)
select Ask as CurrentAsk, AverageAsk, OrderSymbol
FROM cte where Rn = 1
In SQL 2012 and up you can use 
LAST_VALUE function, but be careful http://technet.microsoft.com/en-us/library/hh231517.aspx
E.g.
SELECT DISTINCT LAST_VALUE(Ask) OVER (partition by OrderSymbol ORDER BY RateTime
ROWS BETWEEN UNBOUNDED PRECEDING AND UNBOUNDED FOLLOWING) AS CurrentAsk,
AVG(ask) OVER (partition by OrderSymbol) AS AverageAsk, OrderSymbol
FROM Rates
Although since we need to use DISTINCT in this query I don't know if it's going to perform better than ROW_NUMBER() version of it.
For every expert, there is an equal and opposite expert. - Becker's Law
My blog
My TechNet articles

Similar Messages

  • How to avoid full tablescan with max() function and group by

    Hi Exports,
    This is my query:
    Select max(dID) as dID
    from stellent.Revisions
    Group by dDocName
    Plan
    SELECT STATEMENT CHOOSECost: 3,154 Bytes: 2,336,150 Cardinality: 93,446           
         2 SORT GROUP BY Cost: 3,154 Bytes: 2,336,150 Cardinality: 93,446      
              1 TABLE ACCESS FULL STELLENT.REVISIONS Cost: 632 Bytes: 5,501,700 Cardinality: 220,068
    How can I tune the query ?
    Thanks a lot!

    So I'm assuming it's slow and that's why you're asking for help and not just because it says full table scan. The problem is that you are reading every single row in the table regardless, so the best option is full tablescan. If you don't want to read every row in the table then I would suggest starting with a where clause.

  • Cannot get wanted data with MAX and GROUP BY function

    Hi
    All
    I have a table like below:
    COLUMN     TYPE
    USER_ID     VARCHAR2 (10 Byte)
    PROCESS_ID     VARCHAR2 (30 Byte)
    END_TIME     DATE(STAMP)
    TO_LOC     VARCHAR2 (12 Byte)
    TO_LOC_TYPE     VARCHAR2 (15 Byte)
    FROM_LOC      VARCHAR2 (12 Byte)
    ITEM_ID     VARCHAR2 (25 Byte)
    CASES     NUMBER (12,4)
    LMS_UDA1      VARCHAR2 (250 Byte)
    ZONE     VARCHAR2 (2 Byte)
    I only want get one record with all columns, only have one clause MAX(END_TIME)
    But the other column have difference value.
    when i use MAX(END_TIME) and GROUP BY USER_ID,PROCESS_ID,CASES,....
    the sql didnot give one record,
    It give many records
    Please help me on this
    Regards
    Saven

    Hi, Saven,
    Sorry, it's unclear what you want.
    Whenever you have a question, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    If you can show your proiblem using commonly available tables, like those in the scott or hr schamas, then you don't have to post any sample data: just the results and the explanation.
    Always say what version of Oracle you're using.
    See the forum FAQ {message:id=9360002}
    Are you trying to see all data related to the highest (that is, latest) end_time?
    I think you want something like this, that finds all the ionformation about the employee with the latest hiredate:
    WITH     got_r_num     AS
         SELECT     emp.*
         ,     ROW_NUMBER () OVER (ORDER BY  hiredate  DESC  NULLS LAST)
                   AS r_num
         FROM     scott.emp
    SELECT     *     -- Or list all columns except r_num
    FROM     got_r_num
    WHERE     r_num     = 1
    ;What do you want in case of a tie, that is, if 2 or more rows have the same latest end_time? You may need to add tie-breaking expressions to the analytic ORDER BY clause, and/or use RANK instead of ROW_NUMEBR

  • SNMPv3 user and group dependency?

    HI,
    if i create group with authpriv and user with no authnopriv, and if we add user to this group. what will be result? this user will be authenticated or not? what is the dependency between users and groups ? Which has high priority?
    thanks guys

    Hi. Before I found this answer and the link Vinod Arya provided, I had the same question, so I did some tests in GNS3 configuring different snmpv3 groups within a router cisco 2800 (i.e. a no-auth group, an auth group and a priv group); creating different users with different security levels  and making all the possible combinations between users and groups. After capturing with Wireshark those results (i'll put them at the end of the question) I write a "rule", the "general conclusion" of that dependency between the security level of groups and users, as follows:
    - " Within the agent, the group's security level has precedence over the user's security level member of that group, if the group's security level is greater than the user's security level. This is explained with the following two scenarios. First scenario, If inside the agent, the group which the user belongs, does not have any securities (a noauth group) and the user inside of it has a security level greater, for example, authPriv; an external incoming request to the user of this agent, with authNoPriv security level, will be able to gather the information that was looking for, despite the user inside router's agent has configured both authentication and privacy protocols and keys. Second scenario, the opposite situation. When the group's security level is higher, for example authPriv and the user within the group has a lower security level (for example, a noAuthNoPriv user or a authNoPriv user)  an external incoming request to the user of this agent, with noAuthNoPriv or authNoPriv security level, will get a NULL response to the request.
    That's why concordance must exist between the security level of both the group and the users members of that group.
    Another important consideration is consider the interaction between user's security levels (admin and agents). The security level of the user has precedence over the request's security level of the admin console, because if the security level of the incoming request is higher than the configured for the user who it is asking to, the request won't be successfull and an error message "unsupported security level" will be sent to the admin console."  -
    Please I want to know if the conclusion I reached after the analisis of the results of tests is correct, or if it's imprecise, you can help me to improve it.
    In the link it doesn't say literally that the group has precedence, it mentions about the errors in the case of a missing password or inconsistence between group and user's security level. Also saying that the group's security level has precedence over the user's security level is not always true wich I think was demonstrated with the first scenario example, that's why I need to know if the explanation I wrote is good or is missing something.  Thanks in advance
    Results of the tests: the image provided

  • Max, Min and Count with Group By

    Hello,
    i want the max, min and count of a table, which is grouped by a column
    I need a combination of these two selects:
    select
         max(COUNTRY_S) MAXVALUE,
         min(COUNTRY_S) MINVALUE
    from
         tab_Country
    select
         count(*)
    from
         (select COUNTRY_TXT from tab_Country group by COUNTRY_TXT) ;
    The result should be one row with the max and min value of the table and with the count of the grouped by table, not the max and min of each group! - i hope you understand my question?
    Is this possible in one SQL-select?
    Thank you very much
    Best regards
    Heidi

    Hi, Heidi,
    HeidiWeber wrote:
    Hello,
    i want the max, min and count of a table, which is grouped by a column
    I need a combination of these two selects:
    select 
         max(COUNTRY_S) MAXVALUE, 
         min(COUNTRY_S) MINVALUE 
    from 
         tab_Country 
    select 
         count(*) 
    from 
         (select COUNTRY_TXT from tab_Country group by COUNTRY_TXT) ; 
    The result should be one row with the max and min value of the table and with the count of the grouped by table, not the max and min of each group! - i hope you understand my question?
    Is this possible in one SQL-select?
    Thank you very much
    Best regards
    Heidi
    It's not clear what you want.  Perhaps
    SELECT  MAX (country_s)               AS max_country_s
    ,       MIN (country_s)               AS min_country_s
    ,       COUNT (DISTINCT country_txt)  AS count_country_txt
    FROM    tab_country
    I hope this answers your question.
    If not, post a little sample data (CREATE TABLE and INSERT statements, relevant columns only) for all the tables involved, and the results you want from that data.
    Explain, using specific examples, how you get those results from that data.
    Always say what version of Oracle you're using (e.g. 11.2.0.2.0).
    See the forum FAQ: https://forums.oracle.com/message/9362002

  • PO Line Item wise gross value for combination of WBS and Material Group

    Hello,
    Our requirement is to get report for PO Line Item wise gross value for combination of WBS and Material Group. Standard report ME2J gives net price but not gross value for Material Line items. Please let me know if any standard report( or ME2J) will suffice this requirement.
    Regards,
    Milind Dumbre

    Dear Milind
    No standard report available to get the PO Line Item wise gross value for combination of WBS and Material Group. Please go for development by taking reference ME2J.
    Warm regards
    Ramakrishna

  • How to select records based on Max/Min on different columns and group by

    I have a table with 5 columns(a,b,c,d,e), i need to select records based on MAX(c),Max(D) and Min(e) group by a,b. i am trying using : select max(c),max(d),min(e) from table group by a,b. this is not working. its giving me 1 6 1
    a b c d e
    1 1 1 2 1
    1 1 1 6 4
    1 1 1 6 3
    when i group by a,b i am expecting the record 1 6 3
    Please help me with this.. Thanks in advance....

    Hi,
    Welcome to the forum!
    962163 wrote:
    I have a table with 5 columns(a,b,c,d,e), i need to select records based on MAX(c),Max(D) and Min(e) group by a,b. i am trying using : select max(c),max(d),min(e) from table group by a,b. this is not working. its giving me 1 6 1
    a b c d e
    1 1 1 2 1
    1 1 1 6 4
    1 1 1 6 3
    when i group by a,b i am expecting the record 1 6 3It looks to me like "1 6 1" is the correct answer. You're asking for the lowest value of e, and 1 is lower than 3.
    Maybe you don't want MIN (e). Explain why you want 3 (that is, how you decided that 3 is the correct value for the last column) and someone will help you code it.
    Edited by: Frank Kulash on Sep 28, 2012 6:17 PM
    Whenever you have a problem, you should psot CREATE TABLE and INSERT statements for your sample data. That way, the people who want to help you can re-create the problem and test their ideas. It often helps to clarify the problem, too. since this is your first message, I'll do it for you:
    CREATE TABLE     table_x
    (       a     NUMBER
    ,     b     NUMBER
    ,     c     NUMBER
    ,     d     NUMBER
    ,     e     NUMBER
    INSERT INTO table_x (a, b, c, d, e) VALUES (1, 1, 1, 2, 1);
    INSERT INTO table_x (a, b, c, d, e) VALUES (1, 1, 1, 6, 4);
    INSERT INTO table_x (a, b, c, d, e) VALUES (1, 1, 1, 6, 3);
    COMMIT;

  • Problem in creating group above AND group left in one report!

    Hi all,
    I need a report that is a combination of group above and group
    left.
    Suppose I have 3 table (Emp, Sales, Product):
    Emp Table has 2 column
    - Emp_PK
    - Emp_Name
    Sales Table has 4 column
    -Sales_PK
    -Sales_Date
    -Emp_FK
    -Produck_FK
    -Quantity
    Product Table has 3 column
    -Product_PK
    -Product_Name
    -Product_Price
    I want to make Employee Sales Report For The Month that will
    look like this:
    Emp Number___: Emp_PK
    Emp Name_____: Emp_Name
    Sales Date______Product_Name____Quantity \(2 sales
    ________________Product_Name____Quantity /the date)
    Sales_Date______Product_Name____Quantity
    As you can see this consist of group above (The Employee) and
    group left (The Sales and Product).
    I create this by using 2 queries and link them (the Emp_PK from
    1st query and Emp_FK from 2nd query) on the report builder using
    data link.
    The first query is:
    Select Emp_PK, Emp_Name from Emp
    The second query is
    Select Emp_FK, Sales_Date, Product_Name, Quantity
    From Sales, Product
    Where Product_PK=PRODUCT_FK
    I then create the layout for second query and choose group left
    for Sales_Date using wizard and I create additional layout to
    for the employee.
    The problem is that when I run this report, it will print ALL
    the employee record first (including employee who has NOT sale
    anything) and then on the last page it will print the record of
    Last employee on the Emp table and ALL sales record (including
    those that is done by other employee).
    This report will run correctly if I choose an exact employee
    (For example by adding Where Emp_PK=1111 in the first query) to
    report all of the sales done by this person (employee with emp
    number of 1111). However I need the report to run and print
    ONLY those employee who has Sales Records!
    I thought that by linking the 2 queries in Data Model, it will
    have the same effect as linking using the WHERE clause in query.
    If suppose I create a query like this:
    SELECT Emp_PK, Emp_Name, Sales_Date, Product_Name, Quantity
    FROM Emp, Sales, Product
    WHERE Emp_PK=Emp_FK AND Product_PK=Product_FK
    The report will run OK but I can only choose EITHER group above
    or group left for this ONE query methods in report Wizard.
    Sorry if it is a long question but I hope you can see what I am
    trying to do.
    Thanks in advance for any tip.

    hello,
    of course you can create group left and group above blocks in a
    single report.
    you might want to use the INSERT REPORT BLOCK instead of the
    report wizard, as the report wizard only allows you to use one
    report layout per report, where the report block wizard (invoked
    by INSERT REPORT BLOCK) allows you to choose on a per-block
    basis.
    of course you can create the blocks completely from scarth by
    hand, if you want to.
    regards,
    the oracle reports team --pw                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Group and Group counter in Routing

    Hi all,
    what is group and group counter in routing , how these are used in routing , please explain.
    Regards,
    Joseph.

    Dear Joseph,
    1.Each routing is stored against a group and group counter no.
    2.When we create routing without respect to any material and only by giving the plant,the set of operations gets saved under one
    group counter and group no.
    4.Many materials can be assigned to this same group and group counter no,so that the routing is valid for all the materials included.
    5.When you create a routing for material specific,the set of operation gets saved in a group no and group counter no as 01,when
    you create another routing with another set of operations for the same material,plant and task list combination now the group no
    remains same and the group counter gets saved under 02.
    6.This data can be further helpful in assigning the routing data in the production version,.
    Check and revert
    Regards
    S Mangalraj

  • TableModel with SORT and GROUP BY functions solution.

    Hello all,
    I'd like to represent an EnvelopeTableModel. This class is developed to incapsulate another TableModel and allow user to reorder and group data without changing original values and orders.
    It allows to perform multi column sortings and grouping and
    supports following group functions: EMPTY, COUNT, MIN, MAX, SUM, AVG.
    Here you can download the library, demo version and documentation.
    http://zaval.org/products/swing/
    It would be great to know all your opinions.
    With best regards
    Stanislav Lapitsky

    About 1) and 3).
    These suggestions are almost the same. These features will change GUI component but i want to improve TableModel instead of JTable.
    Using the model user can use JTable for data representation.
    Of course I can improve JTable component and add multiline row/column headers with ability to reorder/group data from component and a lot of another widgets but it isn't my goal.
    About 2) What do you mean "crosstab"?
    Thanks for your 2-cents :-).
    With best regards
    Stas

  • Passing where and group by clause to cursor

    I am working on a procedure that builds a where clause and needs a group by clause to return the correct results. I am trying to pass both the where and group by variables into the cursor.
    The variables are getting populated correctly, but when the cursor gets created, the variables are not in the cursor.
    Here is the code I'm working with. It is a part of a package, but makes no calls to other parts of the package.
    PROCEDURE createFollowUpTask_Exposure( psUppgkedjetyp IN tis.tial.uppgkedjetyp%TYPE default NULL,
    psAlarmtyp IN tis.tial.alarmtyp%TYPE default NULL,
    psSubtyp IN tis.tial.subtyp%TYPE default NULL,
    pnDays IN NUMBER default NULL,
    psKampkod IN tis.tiin.kampkod%TYPE default NULL,
    psKatnr IN tis.tiin.katnr%TYPE default NULL,
    psUtgava IN tis.tiin.utgava%TYPE default NULL,
    psKatslag IN tis.tikg.katslag%TYPE default NULL,
    psProdsyst IN tis.tikg.prodsyst%TYPE default NULL,
    psUppgtyp IN tis.tiin.uppgtyp%TYPE default NULL,
    psProdkod IN tis.tiin.prodkod%TYPE default NULL,
    psStatus IN tis.tiin.status%TYPE default NULL
    ) AS
    cTIAL tis.tial%ROWTYPE;
    vLopnr tis.tial.lopnr%TYPE;
    vSqlWhere VARCHAR2(4000);
    vGroupBy VARCHAR2(1000) := ' tiin.kampkod, tiin.abnr, tiko.fordsalj';
    cSelectCursor SYS_REFCURSOR;
    vSqlSelect VARCHAR2(4000);
    psDays VARCHAR2(50);
    cRec T_TIAL_REC;
    nCount number := 0;
    CURSOR cSqlSelect( SqlWhere IN VARCHAR2, GroupBy IN VARCHAR2) IS
    SELECT tiin.kampkod, tiin.abnr, tiko.fordsalj, MAX(tici.regdat) ALARMDATE
    FROM tis.tiin
    JOIN tis.tiko ON tiin.kampkod = tiko.kampkod AND tiin.abnr = tiko.abnr
    JOIN core.tici ON tiin.kampkod = tici.kampkod AND tiin.abnr = tici.abnr AND tici.inplnr = tiin.inplnr
    WHERE 1=1 || SqlWhere
    GROUP BY GroupBy;
    BEGIN
    -- If these parameters are null, raise error
    IF psUppgkedjetyp IS NULL and psSubtyp IS NULL THEN
    raise_application_error(-20001,
    'Either Event Chain or Starting Event must be assigned');
    END IF;
    -- Populate TIAL values
    IF psUppgkedjetyp IS NOT NULL THEN
    cTIAL.Uppgkedjetyp := psUppgkedjetyp;
    END IF;
    IF psAlarmtyp IS NOT NULL THEN
    cTIAL.Alarmtyp := psAlarmtyp;
    END IF;
    cTIAL.Handklass := 'T';
    cTIAL.Blobid := 0;
    IF pnDays IS NOT NULL THEN
    psDays := '+ '||pnDays;
    END IF;
    IF psSubtyp IS NOT NULL THEN
    cTIAL.Subtyp := psSubtyp;
    END IF;
    -- Create Where clause for cursor
    vSqlWhere := '';
    IF psKampkod IS NOT NULL THEN
    vSqlWhere := vSqlWhere||' AND tiin.kampkod = '''|| psKampkod||'''';
    END IF;
    IF psKatnr IS NOT NULL THEN
    vSqlWhere := vSqlWhere||' AND tiin.katnr = '''||psKatnr||'''';
    END IF;
    IF psUtgava IS NOT NULL THEN
    vSqlWhere := vSqlWhere||' AND tiin.utgava = '''||psUtgava||'''' ;
    END IF;
    IF psKatslag IS NOT NULL THEN
    vSqlWhere := vSqlWhere||' AND tikg.katslag = '''||psKatslag||'''';
    END IF;
    IF psProdsyst IS NOT NULL THEN
    vSqlWhere := vSqlWhere||' AND tikg.prodsyst = '''||psProdsyst||'''';
    END IF;
    IF psUppgtyp IS NOT NULL THEN
    vSqlWhere := vSqlWhere||' AND tiin.uppgtyp = '''||psUppgtyp||'''';
    END IF;
    IF psProdkod IS NOT NULL THEN
    vSqlWhere := vSqlWhere||' AND tiin.prodkod = '''||psProdkod||'''';
    END IF;
    IF psStatus IS NOT NULL THEN
    vSqlWhere := vSqlWhere||' AND tiin.status = '''||psStatus||'''';
    END IF;
    -- Loop through all records meeting input parameters and set required TIAL values.
    FOR i IN cSqlSelect(vSqlWhere, vGroupBy)
    LOOP
    --FETCH cSelectCursor INTO cRec;             
    cTIAL.Kampkod := '';
    cTIAL.Abnr := '';
    cTIAL.Sign := '';
    cTIAL.Alarmdate := '';
    cTIAL.Kampkod := i.Kampkod;
    cTIAL.Abnr := i.Abnr;
    cTIAL.Sign := i.fordsalj;
    cTIAL.Alarmdate := i.alarmdate;
    nCount := nCount + 1;
    IF vLopnr = -1 THEN
    raise_application_error(-20002,
    'Error Creating task for: '||cTIAL.Kampkod||' '||cTIAL.Abnr||' Sales Rep: '||cTIAL.Alarmdate);
    END IF;
    END LOOP;
    DBMS_OUTPUT.PUT_LINE('I created '||nCount||' records.');
    END createFollowUpTask_Exposure;
    Thanks in advance for any help.

    Hi,
    Welcome to the forum!
    Try this (not tested) as an example:
    PROCEDURE createFollowUpTask_Exposure(psUppgkedjetyp IN tis.tial.uppgkedjetyp%TYPE DEFAULT NULL,
                                          psAlarmtyp     IN tis.tial.alarmtyp%TYPE DEFAULT NULL,
                                          psSubtyp       IN tis.tial.subtyp%TYPE DEFAULT NULL,
                                          pnDays         IN NUMBER DEFAULT NULL,
                                          psKampkod      IN tis.tiin.kampkod%TYPE DEFAULT NULL,
                                          psKatnr        IN tis.tiin.katnr%TYPE DEFAULT NULL,
                                          psUtgava       IN tis.tiin.utgava%TYPE DEFAULT NULL,
                                          psKatslag      IN tis.tikg.katslag%TYPE DEFAULT NULL,
                                          psProdsyst     IN tis.tikg.prodsyst%TYPE DEFAULT NULL,
                                          psUppgtyp      IN tis.tiin.uppgtyp%TYPE DEFAULT NULL,
                                          psProdkod      IN tis.tiin.prodkod%TYPE DEFAULT NULL,
                                          psStatus       IN tis.tiin.status%TYPE DEFAULT NULL) AS
       cTIAL         tis.tial%ROWTYPE;
       vLopnr        tis.tial.lopnr%TYPE;
       vSqlWhere     VARCHAR2(4000);
       vGroupBy      VARCHAR2(1000) := ' tiin.kampkod, tiin.abnr, tiko.fordsalj';
       cSelectCursor SYS_REFCURSOR;
       vSqlSelect    VARCHAR2(4000);
       psDays        VARCHAR2(50);
       cRec          T_TIAL_REC;
       nCount        NUMBER := 0;
       FUNCTION fnc_cSqlSelect(SqlWhere IN VARCHAR2,
                               GroupBy  IN VARCHAR2) RETURN VARCHAR2 IS
       BEGIN
          RETURN 'SELECT tiin.kampkod,
                 tiin.abnr,
                 tiko.fordsalj,
                 MAX(tici.regdat) ALARMDATE
            FROM tis.tiin
            JOIN tis.tiko ON tiin.kampkod = tiko.kampkod
                         AND tiin.abnr = tiko.abnr
            JOIN core.tici ON tiin.kampkod = tici.kampkod
                          AND tiin.abnr = tici.abnr
                          AND tici.inplnr = tiin.inplnr
           WHERE 1 = 1 ' || SqlWhere || ' GROUP BY ' || GroupBy;
       END fnc_cSqlSelect;
    BEGIN
       -- If these parameters are null, raise error
       IF psUppgkedjetyp IS NULL AND psSubtyp IS NULL THEN
          raise_application_error(-20001,
                                  'Either Event Chain or Starting Event must be assigned');
       END IF;
       -- Populate TIAL values
       IF psUppgkedjetyp IS NOT NULL THEN
          cTIAL.Uppgkedjetyp := psUppgkedjetyp;
       END IF;
       IF psAlarmtyp IS NOT NULL THEN
          cTIAL.Alarmtyp := psAlarmtyp;
       END IF;
       cTIAL.Handklass := 'T';
       cTIAL.Blobid    := 0;
       IF pnDays IS NOT NULL THEN
          psDays := '+ ' || pnDays;
       END IF;
       IF psSubtyp IS NOT NULL THEN
          cTIAL.Subtyp := psSubtyp;
       END IF;
       -- Create Where clause for cursor
       vSqlWhere := '';
       IF psKampkod IS NOT NULL THEN
          vSqlWhere := vSqlWhere || ' AND tiin.kampkod = ''' || psKampkod || '''';
       END IF;
       IF psKatnr IS NOT NULL THEN
          vSqlWhere := vSqlWhere || ' AND tiin.katnr = ''' || psKatnr || '''';
       END IF;
       IF psUtgava IS NOT NULL THEN
          vSqlWhere := vSqlWhere || ' AND tiin.utgava = ''' || psUtgava || '''';
       END IF;
       IF psKatslag IS NOT NULL THEN
          vSqlWhere := vSqlWhere || ' AND tikg.katslag = ''' || psKatslag || '''';
       END IF;
       IF psProdsyst IS NOT NULL THEN
          vSqlWhere := vSqlWhere || ' AND tikg.prodsyst = ''' || psProdsyst || '''';
       END IF;
       IF psUppgtyp IS NOT NULL THEN
          vSqlWhere := vSqlWhere || ' AND tiin.uppgtyp = ''' || psUppgtyp || '''';
       END IF;
       IF psProdkod IS NOT NULL THEN
          vSqlWhere := vSqlWhere || ' AND tiin.prodkod = ''' || psProdkod || '''';
       END IF;
       IF psStatus IS NOT NULL THEN
          vSqlWhere := vSqlWhere || ' AND tiin.status = ''' || psStatus || '''';
       END IF;ç
       -- Loop through all records meeting input parameters and set required TIAL values.
       OPEN cSelectCursor FOR fnc_cSqlSelect(vSqlWhere,
                                             vGroupBy);
       LOOP
          FETCH cSelectCursor
             INTO v; -- You must define a variable 'v' to hold the data of cursor
          EXIT WHEN cSelectCursor%NOTFOUND;
          --FETCH cSelectCursor INTO cRec;
          cTIAL.Kampkod   := '';
          cTIAL.Abnr      := '';
          cTIAL.Sign      := '';
          cTIAL.Alarmdate := '';
          cTIAL.Kampkod   := i.Kampkod;
          cTIAL.Abnr      := i.Abnr;
          cTIAL.Sign      := i.fordsalj;
          cTIAL.Alarmdate := i.alarmdate;
          nCount := nCount + 1;
          IF vLopnr = -1 THEN
             raise_application_error(-20002,
                                     'Error Creating task for: ' || cTIAL.Kampkod || ' ' ||
                                     cTIAL.Abnr || ' Sales Rep: ' || cTIAL.Alarmdate);
          END IF;
       END LOOP;
       CLOSE cSelectCursor;
       DBMS_OUTPUT.PUT_LINE('I created ' || nCount || ' records.');
    END createFollowUpTask_Exposure;
    /Regards,

  • Execution sequence of connect by and group by

    Hi All,
    I know 'connect by' precedes 'where clause'. And I can use a test case to test this.
    But I can't figure out which comes first, connect by and group by.
    Can someone give me some tips on this, pleaes?
    And another confusion of mine is execution sequence of select and order by.
    In my opinion, since order by can read the alias of selected column, I think the sequence is that oracle select rows first and then sort them.
    Please correct or confirm my statement.
    Best regards,
    Leon

    Hi, Leon,
    user12064076 wrote:
    Hi All,
    I know 'connect by' precedes 'where clause'. And I can use a test case to test this.
    But I can't figure out which comes first, connect by and group by. Can you figure out if WHERE precedes GROUP BY?
    SELECT    job
    ,         COUNT (*)   AS cnt
    FROM      scott.emp
    WHERE     sal     < 2500
    GROUP BY  job
    ;Aggregate functions, like COUNT, are evaluated as the GROUP BY clause is being performed. After the GROUP BY clause, only the ABC's (<b>A</b>ggregates, Group <b>B</b>Y expressions, <b>C</b>onstants, and <b>D</b>eterministic combinations of these) can be referenced.
    Can someone give me some tips on this, pleaes? Consider this query:
    SELECT     LEVEL
    ,     COUNT (*)     AS cnt
    FROM     scott.emp
    START WITH     mgr     IS NULL
    CONNECT BY     mgr     = PRIOR empno
    GROUP BY     LEVEL
    ;Output:
    `    LEVEL        CNT
             1          1
             2          3
             4          2
             3          8
    And another confusion of mine is execution sequence of select and order by.
    In my opinion, since order by can read the alias of selected column, I think the sequence is that oracle select rows first and then sort them.
    Please correct or confirm my statement. Yes, the ORDER BY clause is evaluated after the SELECT clause. The ability to reference column aliases in the ORDER BY clause hints at this. Also, you can say
    ORDER BY  1

  • Contacts and groups

    is there a maximum number of contacts? is there a max # of contacts per group?
    i want to set up some large email lists - if there is a max on verizon.net , will it work if i do it in outlook?
    Solved!
    Go to Solution.

    For your verizon.net addressbook, you have a max of 300 entries. That includes individuals AND groups. So if you have 38 contacts and two groups, that makes 40 entries. If you use an email client, you will not have this restriction.
    You cannot send to more than 100 contacts at a time using Verizon's servers, and no more than 500 in an hour. This is stated in their email policy here.
    The following limits apply with respect to the sending of e-mail from your verizon.net e-mail account. These rules are in place in order to help fight spam (i.e., unsolicited e-mail). For more information on Verizon Online's efforts to fight spam, please see the Verizon Online Anti-Spam Policy.
    You may not include more than 100 recipients in a single email. Messages will not be sent to any recipients in excess of 100.
    You may not exceed 500 recipients in 1 hour. Exceeding 500 recipients in 1 hour will result in the suspension of your ability to send email for 24 hours. This does not affect your ability to receive email.
    It is important to note that the restrictions on the number of recipients/messages apply regardless of whether you use verizon.net or an email client. If you need to send more messages, I'd suggest finding another outgoing server to use.
    If a forum member gives an answer you like, give them the Kudos they deserve. If a member gives you the answer to your question, mark the answer as Accepted Solution so others can see the solution to the problem.
    "All knowledge is worth having."

  • Billing experts: Combining order related and deliv. related

    Hello Billing experts,
    I am just wondering if it is possible at all to combine order related and delivery related to ONE billing document (one DMR and one delivery note with the same payer).
    Or do we have to use Invoice List? I can't make it work.
    Same payer, same Payment Terms and different pricing procedures(with RL00). What other fields that must have identical values, so the billing documents will be grouped in the invoice list?
    Thanks alot in advance!
    Best Regards,
    Tuan Vo

    Hi Tuan Vo
    Since there are many other criteria, its not a viable Solution to combine, order related and delivery related to one billing document even though its possible in SAP.
    The following prerequisites must be met for a Single Invoice from Delivers and/or orders:
    1) the header data appearing in the billing document must agree
    2) the split conditions specified do not apply
    As you see, the Delivery related Invoice has always a pre-checking with the Goods Issue status where as Order related doesn't have to.
    Hence Invoice lists is the option given by SAP.
    However, with an intelligent Copy Control routines between the documents should do the trick.
    The system combines documents with the same customer number, proposal billing type and sales organization, and attempts to include them all in the same billing document. If the preconditions are met, then a single invoice is created for the deliveries and/or orders.
    Note that When creating several billing documents, user exits can be used to reset the header data, so that more can be combined than in the billing due list and later combine to single document.
    There are other fields like Material Group, Billing Dates, Billing Document Type, Item categories which can force for an Invoice split.
    Please let me know if it helps.
    Best Regards
    Ajay Kumar Veeranki

  • User and Group Preferences pane error

    I am having difficulty with the Users and Groups in Lion.  I did not notice this problem. I can add any users. When I click on users it simply gives t=me the message that It cant open the Users preference pane. Any Ideas?

    Launch the Terminal application in any of the following ways:
    ☞ Enter the first few letters of its name into a Spotlight search. Select it in the results (it should be at the top.)
    ☞ In the Finder, select Go ▹ Utilities from the menu bar, or press the key combination shift-command-U. The application is in the folder that opens.
    ☞ If you’re running Mac OS X 10.7 or later, open LaunchPad. Click Utilities, then Terminal in the page that opens.
    Drag or copy – do not type – the following line into the Terminal window, then press return:
    dscl . -list /Users | grep Guest
    Post the lines of output that appear below what you entered, if any – the text, please, not a screenshot.

Maybe you are looking for