Group By, Sort operation on pl/sql collection

Hi,
Is it possible to do a group by or a order by operation on a pl/sql table of records?
Thanks,
Ashish

If you are building your cllection from a database then why dont you SORT in the SQL that you use toget data from the database. If that dose not help then this link will help you.
sort data of pl/sql table
Thanks

Similar Messages

  • Double WINDOW SORT Operation

    Please review following SQL and it's execution plan. Why am I seeing 2 WINDOW SORT operations even though in sql . analytic function "row_number" has been used only once?
    Also, In step 3 of the plan, why "bytes" goes from 35 GB(4th step) to 88GB when row count remains the same. In fact , since I'm selecting just 1st row , both row count as well as "bytes" should have gone down. Shouldn't it?
      SELECT orddtl.ord_dtl_key, orddtl.ld_nbr, orddtl.actv_flg,
             orddtl.ord_nbr
         FROM (SELECT /*+ parallel(od, 8) parallel(sc,8) */  od.ord_dtl_key, od.ld_nbr, od.actv_flg,
                      od.ord_nbr,
                      ROW_NUMBER () OVER (PARTITION BY od.ord_dtl_key, od.START_TS ORDER BY sc.START_TS DESC)
                                                                          rownbr
                 FROM edw.order_detail od LEFT OUTER JOIN edw.srvc_code sc
                      ON (    sc.srvc_cd_key = od.srvc_cd_key
                          AND od.part_nbr = sc.part_nbr
                          AND od.item_cre_dt >= sc.START_TS
                          AND od.item_cre_dt < sc.END_TS
                WHERE od.part_nbr = 11 ) orddtl
        WHERE orddtl.rownbr = 1;Execution Plan
    | Id  | Operation                      | Name              | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     | Pstart| Pstop |    TQ  |IN-OUT| PQ Distrib |
    |   0 | SELECT STATEMENT               |                   |    88M|   121G|       |  2353K (65)| 00:33:07 |       |       |        |      |            |
    |   1 |  PX COORDINATOR                |                   |       |       |       |            |          |       |       |        |      |            |
    |   2 |   PX SEND QC (RANDOM)          | :TQ10002          |    88M|   121G|       |  2353K (65)| 00:33:07 |       |       |  Q1,02 | P->S | QC (RAND)  |
    |*  3 |    VIEW                        |                   |    88M|   121G|       |  2353K (65)| 00:33:07 |       |       |  Q1,02 | PCWP |            |
    |*  4 |     WINDOW SORT PUSHED RANK    |                   |    88M|    35G|    75G|  2353K (65)| 00:33:07 |       |       |  Q1,02 | PCWP |            |
    |   5 |      PX RECEIVE                |                   |    88M|    35G|       |  2353K (65)| 00:33:07 |       |       |  Q1,02 | PCWP |            |
    |   6 |       PX SEND HASH             | :TQ10001          |    88M|    35G|       |  2353K (65)| 00:33:07 |       |       |  Q1,01 | P->P | HASH       |
    |*  7 |        WINDOW CHILD PUSHED RANK|                   |    88M|    35G|       |  2353K (65)| 00:33:07 |       |       |  Q1,01 | PCWP |            |
    |*  8 |         HASH JOIN RIGHT OUTER  |                   |    88M|    35G|       |  1610K (92)| 00:22:39 |       |       |  Q1,01 | PCWP |            |
    |   9 |          PX RECEIVE            |                   |  1133K|    32M|       |  1197  (20)| 00:00:02 |       |       |  Q1,01 | PCWP |            |
    |  10 |           PX SEND BROADCAST    | :TQ10000          |  1133K|    32M|       |  1197  (20)| 00:00:02 |       |       |  Q1,00 | P->P | BROADCAST  |
    |  11 |            PX BLOCK ITERATOR   |                   |  1133K|    32M|       |  1197  (20)| 00:00:02 |   KEY |   KEY |  Q1,00 | PCWC |            |
    |  12 |             TABLE ACCESS FULL  |  SRVC_CODE        |  1133K|    32M|       |  1197  (20)| 00:00:02 |     1 |     1 |  Q1,00 | PCWP |            |
    |  13 |          PX BLOCK ITERATOR     |                   |    88M|    32G|       |   188K (27)| 00:02:39 |   KEY |   KEY |  Q1,01 | PCWC |            |
    |  14 |           TABLE ACCESS FULL    |    ORDER_DETAIL   |    88M|    32G|       |   188K (27)| 00:02:39 |     1 |     1 |  Q1,01 | PCWP |            |
    Predicate Information (identified by operation id):
       3 - filter("orddtl"."rownbr"=1)
       4 - filter(ROW_NUMBER() OVER ( PARTITION BY "od"."ORD_DTL_KEY","od"."START_TS" ORDER BY INTERNAL_FUNCTION("SC"."START_TS"(+))
                  DESC )<=1)
       7 - filter(ROW_NUMBER() OVER ( PARTITION BY "od"."ORD_DTL_KEY","od"."START_TS" ORDER BY INTERNAL_FUNCTION("SC"."START_TS"(+))
                  DESC )<=1)
       8 - access("od"."part_nbr"="SC"."part_nbr"(+) AND "SC"."SRVC_CD_KEY"(+)="od"."SRVC_CD_KEY")
           filter("od"."ITEM_CRE_DT"<"SC"."END_TS"(+) AND "od"."ITEM_CRE_DT">="SC"."START_TS"(+))

    Thanks Jonathan for your reply.
    This type of pattern happens quite frequently in parallel execution with aggregation. A layer of slave processes can do partial aggregation before passing a reduced result set to the query co-ordinator to finish the job.
    I wouldn't be 100% sure without building a model to check, but I think the logic of your quer allows the eight slaves to identify each "rownumber() = 1" for the data set they have collected, and the allows the query coordinator to do the window sort on the eight incoming rows (for each key) and determine which one of the eight is ultimate the highest date.So is it a normal pattern? Will step#7 & #4 do the same amount work as stated in PREDICATE information part of execution plan.?
    You’re correct! There are 8 slave processes appears to be performing WINDOW PUSHED RANK ( Step#7 in Execution Plan ) as you see in following output. Per execution plan and your comment, each one appears to be finding partial set of rows row_num <= 1. It’s apparently doing lots of work and very slow even with 8 processes. So not sure , how slow would be QC doing the same work just by itself.
    And as you see below , it’s [Step#7 ] very slow and half of the slaves performing multi pass sort operation. Even though , it was estimated 35GB for that operation, why it’s estimating work area size of only 6-14MB only? Also, It’s allocating so low amount of PGA than expected. P_A_T was set to approx 11 GB. Currently this was the only query/operation on the Instance.
    Why it’s not allocating more PGA for that operation? [My apologies for diverting from my original question ].
    I have included PGA stats as well here which was taken 5-10 minutes later than other PQ session information. It’s still shows that there is no shortage of PGA.
    Moreover, I have observed this behavior (under allocation of PGA) especially for WINDOWS SORT operations for other SQLs too. Is it normal behavior ? I’m on 10.2.0.4.
    select
    decode(px.qcinst_id,NULL,username,
    ' - '||lower(substr(pp.SERVER_NAME,
    length(pp.SERVER_NAME)-4,4) ) )"Username",
    decode(px.qcinst_id,NULL, 'QC', '(Slave)') "QC/Slave" ,
    to_char( px.server_set) "SlaveSet",
    to_char(s.sid) "SID",
    to_char(px.inst_id) "Slave INST",
    decode(sw.state,'WAITING', 'WAIT', 'NOT WAIT' ) as STATE,
    case  sw.state WHEN 'WAITING' THEN substr(sw.event,1,30) ELSE NULL end as wait_event ,
    to_char(s.ROW_WAIT_OBJ#)  wait_OBID,
    decode(px.qcinst_id, NULL ,to_char(s.sid) ,px.qcsid) "QC SID",
    to_char(px.qcinst_id) "QC INST",
    px.req_degree "Req. DOP",
    px.degree "Actual DOP"
    from gv$px_session px,
    gv$session s ,
    gv$px_process pp,
    gv$session_wait sw
    where px.sid=s.sid (+)
    and px.serial#=s.serial#(+)
    and px.inst_id = s.inst_id(+)
    and px.sid = pp.sid (+)
    and px.serial#=pp.serial#(+)
    and sw.sid = s.sid
    and sw.inst_id = s.inst_id
    order by
      decode(px.QCINST_ID,  NULL, px.INST_ID,  px.QCINST_ID),
      px.QCSID,
      decode(px.SERVER_GROUP, NULL, 0, px.SERVER_GROUP),
      px.SERVER_SET,
      px.INST_ID
    UNAME        QC/Slave SlaveSet SID       Slave INS STATE    WAIT_EVENT                      WAIT_OBID QC SID QC INS Req. DOP Actual DOP
    APPS_ORD     QC                1936      2         WAIT     PX Deq: Execute Reply          71031      1936
    - p006      (Slave)  1        1731      2         WAIT     PX Deq: Execution Msg          71021      1936   2             8          8
    - p007      (Slave)  1        2159      2         WAIT     PX Deq: Execution Msg          71021      1936   2             8          8
    - p002      (Slave)  1        2090      2         WAIT     PX Deq: Execution Msg          71021      1936   2             8          8
    - p005      (Slave)  1        1965      2         WAIT     PX Deq: Execution Msg          71021      1936   2             8          8
    - p001      (Slave)  1        1934      2         WAIT     PX Deq: Execution Msg          71021      1936   2             8          8
    - p004      (Slave)  1        1843      2         WAIT     PX Deq: Execution Msg          71021      1936   2             8          8
    - p000      (Slave)  1        1778      2         WAIT     PX Deq: Execution Msg          71021      1936   2             8          8
    - p003      (Slave)  1        1751      2         WAIT     PX Deq: Execution Msg          71021      1936   2             8          8
    - p009      (Slave)  2        2138      2         NOT WAIT                                71031      1936   2             8          8
    - p012      (Slave)  2        1902      2         NOT WAIT                                71031      1936   2             8          8
    - p008      (Slave)  2        1921      2         NOT WAIT                                71031      1936   2             8          8
    - p013      (Slave)  2        2142      2         NOT WAIT                                71031      1936   2             8          8
    - p015      (Slave)  2        2091      2         NOT WAIT                                71031      1936   2             8          8
    - p014      (Slave)  2        2122      2         NOT WAIT                                71031      1936   2             8          8
    - p010      (Slave)  2        2146      2         NOT WAIT                                71031      1936   2             8          8
    - p011      (Slave)  2        1754      2         NOT WAIT                                71031      1936   2             8          8
    SELECT operation_type AS type                      ,
            workarea_address WADDR,
            operation_id as OP_ID,
            policy                                      ,
            vwa.sql_id,
            vwa.inst_id i#,
            vwa.sid                                     ,
            vwa.qcsid   QCsID,
            vwa.QCINST_ID  QC_I#,
            s.username uname,
            ROUND(active_time    /1000000,2)   AS a_sec ,
            ROUND(work_area_size /1024/1024,2) AS wsize ,
            ROUND(expected_size  /1024/1024,2) AS exp   ,
            ROUND(actual_mem_used/1024/1024,2) AS act   ,
            ROUND(max_mem_used   /1024/1024,2) AS MAX   ,
            number_passes                      AS p#,
            ROUND(tempseg_size/1024/1024,2)    AS temp
    FROM   gv$sql_workarea_active vwa ,
            gv$session s
    where  vwa.sid = s.sid
    and    vwa.inst_id = s.inst_id
    order by vwa.sql_id, operation_id, vwa.inst_id, username, vwa.qcsid
    TYPE            WADDR            OP_ID POLI SQL_ID         I#    SID  QCSID QC_I# UNAME                A_SEC      WSIZE        EXP        ACT        MAX   P#       TEMP
    WINDOW (SORT)   07000003D2B03F90     7 AUTO 8z5s5wdy94ty3   2   2146   1936     2 APPS_ORD            1181.22      13.59      13.59       7.46      90.98    1        320
    WINDOW (SORT)   07000003D2B03F90     7 AUTO 8z5s5wdy94ty3       2142   1936     2 APPS_ORD            1181.07       7.03       7.03       4.02      90.98    0        288
    WINDOW (SORT)   07000003D2B03F90     7 AUTO 8z5s5wdy94ty3       2091   1936     2 APPS_ORD            1181.06       7.03       7.03        4.5      90.98    0        288
    WINDOW (SORT)   07000003D2B03F90     7 AUTO 8z5s5wdy94ty3       1921   1936     2 APPS_ORD            1181.09      13.59      13.59       2.24      90.98    1        320
    WINDOW (SORT)   07000003D2B03F90     7 AUTO 8z5s5wdy94ty3       2138   1936     2 APPS_ORD            1181.16       7.03       7.03       1.34      90.98    0        288
    WINDOW (SORT)   07000003D2B03F90     7 AUTO 8z5s5wdy94ty3       1754   1936     2 APPS_ORD            1181.09      14.06      14.06       5.77      90.98    1        320
    WINDOW (SORT)   07000003D2B03F90     7 AUTO 8z5s5wdy94ty3       2122   1936     2 APPS_ORD            1181.15       6.56       6.56        .24      90.98    0        288
    WINDOW (SORT)   07000003D2B03F90     7 AUTO 8z5s5wdy94ty3       1902   1936     2 APPS_ORD            1181.12      14.06      14.06       9.12      90.98    1        320
    HASH-JOIN       07000003D2B03F28     8 AUTO 8z5s5wdy94ty3       2142   1936     2 APPS_ORD            1183.24      98.64      98.64     100.44     100.44    0
    HASH-JOIN       07000003D2B03F28     8 AUTO 8z5s5wdy94ty3       2138   1936     2 APPS_ORD            1183.24      98.64      98.64     100.44     100.44    0
    HASH-JOIN       07000003D2B03F28     8 AUTO 8z5s5wdy94ty3       2122   1936     2 APPS_ORD            1183.24      98.64      98.64     100.44     100.44    0
    HASH-JOIN       07000003D2B03F28     8 AUTO 8z5s5wdy94ty3       2091   1936     2 APPS_ORD            1183.24      98.64      98.64     100.44     100.44    0
    HASH-JOIN       07000003D2B03F28     8 AUTO 8z5s5wdy94ty3       1921   1936     2 APPS_ORD            1183.24      98.64      98.64     100.44     100.44    0
    HASH-JOIN       07000003D2B03F28     8 AUTO 8z5s5wdy94ty3       1902   1936     2 APPS_ORD            1183.24      98.64      98.64     100.44     100.44    0
    HASH-JOIN       07000003D2B03F28     8 AUTO 8z5s5wdy94ty3       2146   1936     2 APPS_ORD            1183.24      98.64      98.64     100.44     100.44    0
    HASH-JOIN       07000003D2B03F28     8 AUTO 8z5s5wdy94ty3       1754   1936     2 APPS_ORD            1183.24      98.64      98.64     100.44     100.44    0
                                                              sum                                                872.07            838.21
    PGA Stats – taken 5-10 minutes later than above.
    select name, decode(unit,'bytes',round(value/1048576,2)||' MB', value) value from v$pgastat
    NAME                                               VALUE
    aggregate PGA target parameter                     11264 MB
    aggregate PGA auto target                          9554.7 MB
    global memory bound                                1024 MB
    total PGA inuse                                    902.21 MB
    total PGA allocated                                3449.64 MB
    maximum PGA allocated                              29155.44 MB
    total freeable PGA memory                          2140.56 MB
    process count                                      107
    max processes count                                379
    PGA memory freed back to OS                        77240169.56 MB
    total PGA used for auto workareas                  254.14 MB
    maximum PGA used for auto workareas                22797.02 MB
    total PGA used for manual workareas                0 MB
    maximum PGA used for manual workareas              16.41 MB
    over allocation count                              0
    bytes processed                                    323796668.77 MB
    extra bytes read/written                           183362312.02 MB
    cache hit percentage                               63.84
    recompute count (total)                            2054320
    SELECT
    PGA_TARGET_FOR_ESTIMATE/1048576 ESTMTD_PGA_MB,
       PGA_TARGET_FACTOR PGA_TGT_FCTR,
       ADVICE_STATUS ADV_STS,
       BYTES_PROCESSED/1048576 ESTMTD_MB_PRCD,
       ESTD_EXTRA_BYTES_RW/1048576 ESTMTD_XTRA_MB,
       ESTD_PGA_CACHE_HIT_PERCENTAGE ESTMTD_CHIT_PCT,
       ESTD_OVERALLOC_COUNT O_ALOC_CNT
    FROM V$PGA_TARGET_ADVICE
    ESTMTD_PGA_MB PGA_TGT_FCTR ADV ESTMTD_MB_PRCD ESTMTD_XTRA_MB ESTMTD_CHIT_PCT O_ALOC_CNT
            1,408         .125 ON     362,905,053    774,927,577              32      19973
            2,816          .25 ON     362,905,053    571,453,995              39        709
            5,632           .5 ON     362,905,053    249,201,001              59          5
            8,448          .75 ON     362,905,053    216,717,381              63          0
           11,264            1 ON     362,905,053    158,762,256              70          0
           13,517          1.2 ON     362,905,053    153,025,642              70          0
           15,770          1.4 ON     362,905,053    153,022,337              70          0
           18,022          1.6 ON     362,905,053    153,022,337              70          0
           20,275          1.8 ON     362,905,053    153,022,337              70          0
           22,528            2 ON     362,905,053    153,022,337              70          0
           33,792            3 ON     362,905,053    153,022,337              70          0
           45,056            4 ON     362,905,053    153,022,337              70          0
           67,584            6 ON     362,905,053    153,022,337              70          0
           90,112            8 ON     362,905,053    153,022,337              70          0

  • Sort Operation in Collections

    Hi All,
    Can any one please explain where and why SORT operation will performed while executing below code?
    PROCEDURE process_all_rows
    IS
    TYPE employees_aat IS TABLE OF employees%ROWTYPE INDEX BY PLS_INTEGER;
    l_employees employees_aat;
    BEGIN
    SELECT * BULK COLLECT INTO l_employees FROM employees;
    FOR index IN 1 .. l_employees.COUNT
    LOOP
    analyze_compensation
    (l_employees(indx));
    END LOOP;
    END process_all_rows;
    The code from below link:
    http://www.oracle.com/technetwork/issue-archive/2008/08-mar/o28plsql-095155.html
    Thanks in advance.

    Red Penyon wrote:
    An associative array (formerly called PL/SQL table or index-by table) is a set of key-value pairs. Each key is a unique index, used to locate the associated value with the syntax variable_name(index).
    The data type of index can be either a string type or PLS_INTEGER. Indexes are stored in sort order, not creation order. For string types, sort order is determined by the initialization parameters NLS_SORT and NLS_COMP.So then associative arrays with name-value pairs where the name is numeric, are not sorted? Why would an associative array indexed by number not be sorted?

  • Confusion in FILTER and SORT operations in the execution plan

    Hi
    I have been working on tuning of a sql query:
    SELECT SUM(DECODE(CR_FLG, 'C', NVL(TOT_AMT, 0), 0)),
           SUM(DECODE(CR_FLG, 'C', 1, 0)),
           SUM(DECODE(CR_FLG, 'R', NVL(TOT_AMT, 0), 0)),
           SUM(DECODE(CR_FLG, 'R', 1, 0)),
           SUM(DECODE(CR_FLG, 'C', NVL(TOT_AMT, 0), -1 * NVL(TOT_AMT, 0))),
           SUM(1)
         FROM TS_TEST
        WHERE SMY_DT BETWEEN TO_DATE(:1, 'DD-MM-YYYY') AND
           TO_DATE(:1, 'DD-MM-YYYY');Table TS_TEST is range partitioned on smy_dt and there is an index on smy_dt column. Explain plan of the query is:
    SQL> explain plan for  SELECT SUM(DECODE(CR_FLG, 'C', NVL(TOT_AMT, 0), 0)),
      2         SUM(DECODE(CR_FLG, 'C', 1, 0)),
      3         SUM(DECODE(CR_FLG, 'R', NVL(TOT_AMT, 0), 0)),
      4         SUM(DECODE(CR_FLG, 'R', 1, 0)),
      5         SUM(DECODE(CR_FLG, 'C', NVL(TOT_AMT, 0), -1 * NVL(TOT_AMT, 0))),
      6         SUM(1)
      7    FROM TS_TEST
      8   WHERE SMY_DT BETWEEN TO_DATE(:1, 'DD-MM-YYYY') AND
      9         TO_DATE(:1, 'DD-MM-YYYY');
    Explained.
    SQL> @E
    PLAN_TABLE_OUTPUT
    Plan hash value: 766961720
    | Id  | Operation                            | Name                | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT                     |                     |     1 |    14 | 15614   (1)| 00:03:08 |       |       |
    |   1 |  SORT AGGREGATE                      |                     |     1 |    14 |            |             |       |       |
    |*  2 |   FILTER                             |                     |       |       |            |          |       |       |
    |   3 |    TABLE ACCESS BY GLOBAL INDEX ROWID| T_TEST             | 79772 |  1090K| 15614   (1)| 00:03:08 | ROWID | ROWID |
    |*  4 |     INDEX RANGE SCAN                 | I_SMY_DT         |   143K|       |   442   (1)| 00:00:06 |       |       |
    Predicate Information (identified by operation id):
       2 - filter(TO_DATE(:1,'DD-MM-YYYY')<=TO_DATE(:1,'DD-MM-YYYY'))
       4 - access("SMY_DT">=TO_DATE(:1,'DD-MM-YYYY') AND "SMY_DT"<=TO_DATE(:1,'DD-MM-YYYY'))
    17 rows selected.
    SQL>I am not able to understand the FILTER & SORT operations. As there is an index on SMY_DT column, so index range scan is fine. But why a FILTER (Step no 2) and SORT (Step no 1) operation after that ?
    Oracle version is 10.2.0.3 on AIX 5.3 64 bit.
    Any other information required please let me know.
    Regards,
    Amardeep Sidhu

    Sort aggregate tells you that there was performed an aggregate operation which returns one row, in opposite to sort order by or hash group by which indicates you have grouping, and there more than one row can be returned.
    SQL> SELECT SUM(comm) FROM emp;
    SUM(COMM)
          2200
    Plan wykonywania
    Plan hash value: 2083865914
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |     1 |     2 |     3   (0)| 00:00:01 |
    |   1 |  SORT AGGREGATE    |      |     1 |     2 |            |          |
    |   2 |   TABLE ACCESS FULL| EMP  |    14 |    28 |     3   (0)| 00:00:01 |
    SQL> SELECT AVG(comm) FROM emp;
    AVG(COMM)
           550
    Plan wykonywania
    Plan hash value: 2083865914
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |     1 |     2 |     3   (0)| 00:00:01 |
    |   1 |  SORT AGGREGATE    |      |     1 |     2 |            |          |
    |   2 |   TABLE ACCESS FULL| EMP  |    14 |    28 |     3   (0)| 00:00:01 |
    SQL> SELECT MIN(comm) FROM emp;
    MIN(COMM)
             0
    Plan wykonywania
    Plan hash value: 2083865914
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |     1 |     2 |     3   (0)| 00:00:01 |
    |   1 |  SORT AGGREGATE    |      |     1 |     2 |            |          |
    |   2 |   TABLE ACCESS FULL| EMP  |    14 |    28 |     3   (0)| 00:00:01 |
    SQL> SELECT deptno, SUM(comm) FROM emp GROUP BY deptno;
        DEPTNO  SUM(COMM)
            30       2200
            20
            10
    Plan wykonywania
    Plan hash value: 4067220884
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |     3 |    15 |     4  (25)| 00:00:01 |
    |   1 |  HASH GROUP BY     |      |     3 |    15 |     4  (25)| 00:00:01 |
    |   2 |   TABLE ACCESS FULL| EMP  |    14 |    70 |     3   (0)| 00:00:01 |
    SQL>Edited by: Łukasz Mastalerz on Jan 14, 2009 11:41 AM

  • Group and sort in group2

    CREATE TABLE [dbo].[Table_1](
    [group] [int] NULL,
    [sort] [int] NULL,
    [Item] [nchar](10) NULL
    ) ON [PRIMARY]
    GO
    INSERT [dbo].[Table_1] ([group], [sort], [Item]) VALUES (1, 1, N'Car ')
    INSERT [dbo].[Table_1] ([group], [sort], [Item]) VALUES (2, 1, N'Bus ')
    INSERT [dbo].[Table_1] ([group], [sort], [Item]) VALUES (1, 0, N'Bike ')
    INSERT [dbo].[Table_1] ([group], [sort], [Item]) VALUES (2, 0, N'Lorry ')
    INSERT [dbo].[Table_1] ([group], [sort], [Item]) VALUES (1, 1, N'Train ')
    INSERT [dbo].[Table_1] ([group], [sort], [Item]) VALUES (1, 1, N'Ship ')
    Data
    My Dataset Query in ssrs table
    Group2 expression
    Group on Group
    Sort on Sort
    Group 1 expression
    Sort on Sort
    First(Item.value ) is not working..  i need to fix in ssrs since this is an an sample data of sp with more columns
      my problem is once group2 is grouped, it is not taking the sort and just dispalying the First item in the sort of the item.
    ShanmugaRaj

    I beg your pardon, but in your example in the insert statement you have 1, 1, Ship , whereas in your report you display 1, 0 , Ship.
    Why not avoid the problem at the source, byt letting T-sql do the work:
    with a ([Group], [FirstSort])
    AS (SELECT [GROUP], MIN(sort) As FirstSort from dbo.Table_1 group by [group])
    select  a.[GROUP], a.FirstSort, c.[Item] AS FirstItem , b.[sort], b.[item]
    from a
    inner join  dbo.table_1 as b on a.[Group] = b.[group]
    inner join dbo.Table_1 as c on a.[Group] = c.[group] and a.[FirstSort] = c.[Sort]
    order by a.[group], b.[sort] -- LEAVE OUT the order BY in the report dataset
    Gives this result (I took the insert statements from your example)
    GROUP FirstSort FirstItem sort item
    1 0 Bike       0 Bike     
    1 0 Bike       1 Car      
    1 0 Bike       1 Train    
    1 0 Bike       1 Ship     
    2 0 Lorry      0 Lorry    
    2 0 Lorry      1 Bus      
    Jan D'Hondt - SQL server BI development
    sorry for that .. will take care heare by
    ShanmugaRaj

  • Buffer(sort) operator

    Hi,
    i'm trying to understand what "buffer sort" operation is in the following explain plan:
    0 SELECT STATEMENT
    -1 MERGE JOIN CARTESIAN
    --2 TABLE ACCESS FULL PLAYS
    --3 BUFFER SORT
    ---4 TABLE ACCESS FULL MOVIE
    In Oracle 9i DataBase Performance Guide and Reference, "buffer sort" is not mentioned although all other explain plan's operations are.
    What does it mean? Does it take place in main memory or is it an external sort?
    Thank you.

    A BUFFER SORT typically means that Oracle reads data blocks into private memory,because the block will be accessed multiple times in the context of the SQL statement execution. in other words, Oracle sacrifies some extra memory to
    reduce the overhead of accessing blocks multiple times in shared memory.
    Hope this will clear your doubts.
    Thanks.

  • Group and Sort

    Hi, I am a new PPM user I am trying to group my activities but the Group and Sort window does not respond.  Any ideas?

    I beg your pardon, but in your example in the insert statement you have 1, 1, Ship , whereas in your report you display 1, 0 , Ship.
    Why not avoid the problem at the source, byt letting T-sql do the work:
    with a ([Group], [FirstSort])
    AS (SELECT [GROUP], MIN(sort) As FirstSort from dbo.Table_1 group by [group])
    select  a.[GROUP], a.FirstSort, c.[Item] AS FirstItem , b.[sort], b.[item]
    from a
    inner join  dbo.table_1 as b on a.[Group] = b.[group]
    inner join dbo.Table_1 as c on a.[Group] = c.[group] and a.[FirstSort] = c.[Sort]
    order by a.[group], b.[sort] -- LEAVE OUT the order BY in the report dataset
    Gives this result (I took the insert statements from your example)
    GROUP FirstSort FirstItem sort item
    1 0 Bike       0 Bike     
    1 0 Bike       1 Car      
    1 0 Bike       1 Train    
    1 0 Bike       1 Ship     
    2 0 Lorry      0 Lorry    
    2 0 Lorry      1 Bus      
    Jan D'Hondt - SQL server BI development
    sorry for that .. will take care heare by
    ShanmugaRaj

  • Swap, temporary tablespace and sort operations

    Hello.
    I have an Oracle 8.1.7 on Linux RH7.1. I see a very interesting situation: when users begin to execute large selects with many sorts operation swapping grows, but temporary tablespace does'nt grow. As I know, when Oracle has no memory to use as "sort_area_size" it uses temporary tablespace. But looks like that when Oracle ask for memory Linux begin to swap (in order to give memory for Oracle). I mean that Oracle don't use temporary tablespace but use swap instead of it. Is it true? Is it problem? Is it Oracle, Linux or my own configuration bug? Is it better to use swap or to use temporary tablespace? What is faster?
    Thanx for all advises and ideas. ANd sorry for pure English

    login to your database as DBA (SYS AS SYSDBA) and issue the following query:
    SQL> select name, value from v$parameter where name = 'sga_max_size' ;
    see the value defined for this parameter. If this is larger than what you have configured as your SGA size,
    Oracle will assume that it can expand the SGA to "sga_max_size" value, and will try to expand the SGA when
    required. This will result in Oracle asking more memory from the linux kernel and then linux starts to use
    the swap space.
    Try changing the value of this parameter and see if it helps.

  • Why Sort operation on clustered columstore index insert?

    Looking at the execution plan for a clustered columnstore index insert I noticed a Sort operation. My T-SQL has no sort and I understand that the clustered columnstore is not a sorted index. Why would there be a Sort operation in the execution plan?
    This is running on:
    Microsoft SQL Server 2014 - 12.0.2000.8 (X64)
     Feb 20 2014 20:04:26
     Copyright (c) Microsoft Corporation
     Enterprise Edition: Core-based Licensing (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) (Hypervisor)

    Hello,
    It's because how a columnstore index works: The index is created & compressed on column Level, not on row level. SQL Server orders the data to have the same data after each other to calculate the compressed index values.
    Olaf Helper
    [ Blog] [ Xing] [ MVP]

  • 10g: parallel pipelined table func. using table(cast(SQL collect.))?

    Hi,
    i try to distribute SQL data objects - stored in a SQL data type TABLE OF <object-Type> - to multiple (parallel) instances of a table function,
    by passing a CURSOR(...) to the table function, which selects from the SQL TABLE OF storage via "select * from TABLE(CAST(<storage> as <storage-type>)".
    But oracle always only uses a single table function instance :-(
    whatever hints i provide or setting i use for the parallel table function (parallel_enable ...)
    Could it be, that this is due to the fact, that my data are not
    globally available, but only in the main thread data?
    Can someone confirm, that it's not possible to start multiple parallel table functions
    for selecting on SQL data type TABLE OF <object>storages?
    Here's an example sqlplus program to show the issue:
    -------------------- snip ---------------------------------------------
    set serveroutput on;
    drop table test_table;
    drop type ton_t;
    drop type test_list;
    drop type test_obj;
    create table test_table
         a number(19,0),
         b timestamp with time zone,
         c varchar2(256)
    create or replace type test_obj as object(
         a number(19,0),
         b timestamp with time zone,
         c varchar2(256)
    create or replace type test_list as table of test_obj;
    create or replace type ton_t as table of number;
    create or replace package test_pkg
    as
         type test_rec is record (
              a number(19,0),
              b timestamp with time zone,
              c varchar2(256)
         type test_tab is table of test_rec;
         type test_cur is ref cursor return test_rec;
         function TF(mycur test_cur)
    return test_list pipelined
    parallel_enable(partition mycur by hash(a));
    end;
    create or replace package body test_pkg
    as
         function TF(mycur test_cur)
    return test_list pipelined
    parallel_enable(partition mycur by hash(a))
    is
              sid number;
              counter number(19,0) := 0;
              myrec test_rec;
              mytab test_tab;
              mytab2 test_list := test_list();
         begin
              select userenv('SID') into sid from dual;
              dbms_output.put_line('test_pkg.TF( sid => '''|| sid || ''' ): enter');
              loop
                   fetch mycur into myRec;
                   exit when mycur%NOTFOUND;
                   mytab2.extend;
                   mytab2(mytab2.last) := test_obj(myRec.a, myRec.b, myRec.c);
              end loop;
              for i in mytab2.first..mytab2.last loop
                   -- attention: saves own SID in test_obj.a for indication to caller
                   --     how many sids have been involved
                   pipe row(test_obj(sid, mytab2(i).b, mytab2(i).c));
                   counter := counter + 1;
              end loop;
              dbms_output.put_line('test_pkg.TF( sid => '''|| sid || ''' ): exit, piped #' || counter || ' records');
         end;
    end;
    declare
         myList test_list := test_list();
         myList2 test_list := test_list();
         sids ton_t := ton_t();
    begin
         for i in 1..10000 loop
              myList.extend; myList(myList.last) := test_obj(i, sysdate, to_char(i+2));
         end loop;
         -- save into the real table
         insert into test_table select * from table(cast (myList as test_list));
         dbms_output.put_line(chr(10) || 'copy ''mylist'' to ''mylist2'' by streaming via table function...');
         select test_obj(a, b, c) bulk collect into myList2
         from table(test_pkg.TF(CURSOR(select /*+ parallel(tab,10) */ * from table(cast (myList as test_list)) tab)));
         dbms_output.put_line('... saved #' || myList2.count || ' records');
         select distinct(tab.a) bulk collect into sids from table(cast (myList2 as test_list)) tab;
         dbms_output.put_line('worker thread''s sid list:');
         for i in sids.first..sids.last loop
              dbms_output.put_line('sid #' || sids(i));
         end loop;
         dbms_output.put_line(chr(10) || 'copy physical ''test_table'' to ''mylist2'' by streaming via table function:');
         select test_obj(a, b, c) bulk collect into myList2
         from table(test_pkg.TF(CURSOR(select /*+ parallel(tab,10) */ * from test_table tab)));
         dbms_output.put_line('... saved #' || myList2.count || ' records');
         select distinct(tab.a) bulk collect into sids from table(cast (myList2 as test_list)) tab;
         dbms_output.put_line('worker thread''s sid list:');
         for i in sids.first..sids.last loop
              dbms_output.put_line('sid #' || sids(i));
         end loop;
    end;
    -------------------- snap ---------------------------------------------
    Here's the output:
    -------------------- snip ---------------------------------------------
    copy 'mylist' to 'mylist2' by streaming via table function...
    test_pkg.TF( sid => '98' ): enter
    test_pkg.TF( sid => '98' ): exit, piped #10000 records
    ... saved #10000 records
    worker thread's sid list:
    sid #98 -- ONLY A SINGLE SID HERE!
    copy physical 'test_table' to 'mylist2' by streaming via table function:
    ... saved #10000 records
    worker thread's sid list:
    sid #128 -- A LIST OF SIDS HERE!
    sid #141
    sid #85
    sid #125
    sid #254
    sid #101
    sid #124
    sid #109
    sid #142
    sid #92
    PL/SQL procedure successfully completed.
    -------------------- snap ---------------------------------------------
    I posted it to newsgroup comp.databases.oracle.server.
    (summary: "10g: parallel pipelined table functions with cursor selecting from table(cast(SQL collection)) doesn't work ")
    But i didn't get a response.
    There i also wrote some background information about my application:
    -------------------- snip ---------------------------------------------
    My application has a #2 steps/stages data selection.
    A 1st select for minimal context base data
    - mainly to evaluate for due driving data records.
    And a 2nd select for all the "real" data to process a context
    (joining much more other tables here, which i don't want to do for non-due records).
    So it's doing stage #1 select first, then stage #2 select - based on stage #1 results - next.
    The first implementation of the application did the stage #1 select in the main session of the pl/sql code.
    And for the stage #2 select there was done a dispatch to multiple parallel table functions (in multiple worker sessions) for the "real work".
    That worked.
    However there was a flaw:
    Between records from stage #1 selection and records from stage #2 selection there is a 1:n relation (via key / foreign key relation).
    Means, for #1 resulting record from stage #1 selection, there are #x records from stage #2 selection.
    That forced me to use "cluster curStage2 by (theKey)".
    Because the worker sessions need to evaluate the all-over status for a context of #1 record from stage #1 and #x records from stage #2
    (so it needs to have #x records of stage #2 together).
    This then resulted in delay for starting up the worker sessions (i didn't find a way to get rid of this).
    So i wanted to shift the invocation of the worker sessions to the stage #1 selection.
    Then i don't need the "cluster curStage2 by (theKey)" anymore!
    But: i also need to do an update of the primary driving data!
    So the stage #1 select is a 'select ... for update ...'.
    But you can't use such in CURSOR for table functions (which i can understand, why it's not possible).
    So i have to do my stage #1 selection in two steps:
    1. 'select for update' by main session and collect result in SQL collection.
    2. pass collected data to parallel table functions
    And for 2. i recognized, that it doesn't start up multiple parallel table function instances.
    As a work-around
    - if it's just not possible to start multiple parallel pipelined table functions for dispatching from 'select * from TABLE(CAST(... as ...))' -
    i need to select again on the base tables - driven by the SQL collection data.
    But before i do so, i wanted to verify, if it's really not possible.
    Maybe i just miss a special oracle hint or whatever you can get "out of another box" :-)
    -------------------- snap ---------------------------------------------
    - many thanks!
    rgds,
    Frank

    Hi,
    i try to distribute SQL data objects - stored in a SQL data type TABLE OF <object-Type> - to multiple (parallel) instances of a table function,
    by passing a CURSOR(...) to the table function, which selects from the SQL TABLE OF storage via "select * from TABLE(CAST(<storage> as <storage-type>)".
    But oracle always only uses a single table function instance :-(
    whatever hints i provide or setting i use for the parallel table function (parallel_enable ...)
    Could it be, that this is due to the fact, that my data are not
    globally available, but only in the main thread data?
    Can someone confirm, that it's not possible to start multiple parallel table functions
    for selecting on SQL data type TABLE OF <object>storages?
    Here's an example sqlplus program to show the issue:
    -------------------- snip ---------------------------------------------
    set serveroutput on;
    drop table test_table;
    drop type ton_t;
    drop type test_list;
    drop type test_obj;
    create table test_table
         a number(19,0),
         b timestamp with time zone,
         c varchar2(256)
    create or replace type test_obj as object(
         a number(19,0),
         b timestamp with time zone,
         c varchar2(256)
    create or replace type test_list as table of test_obj;
    create or replace type ton_t as table of number;
    create or replace package test_pkg
    as
         type test_rec is record (
              a number(19,0),
              b timestamp with time zone,
              c varchar2(256)
         type test_tab is table of test_rec;
         type test_cur is ref cursor return test_rec;
         function TF(mycur test_cur)
    return test_list pipelined
    parallel_enable(partition mycur by hash(a));
    end;
    create or replace package body test_pkg
    as
         function TF(mycur test_cur)
    return test_list pipelined
    parallel_enable(partition mycur by hash(a))
    is
              sid number;
              counter number(19,0) := 0;
              myrec test_rec;
              mytab test_tab;
              mytab2 test_list := test_list();
         begin
              select userenv('SID') into sid from dual;
              dbms_output.put_line('test_pkg.TF( sid => '''|| sid || ''' ): enter');
              loop
                   fetch mycur into myRec;
                   exit when mycur%NOTFOUND;
                   mytab2.extend;
                   mytab2(mytab2.last) := test_obj(myRec.a, myRec.b, myRec.c);
              end loop;
              for i in mytab2.first..mytab2.last loop
                   -- attention: saves own SID in test_obj.a for indication to caller
                   --     how many sids have been involved
                   pipe row(test_obj(sid, mytab2(i).b, mytab2(i).c));
                   counter := counter + 1;
              end loop;
              dbms_output.put_line('test_pkg.TF( sid => '''|| sid || ''' ): exit, piped #' || counter || ' records');
         end;
    end;
    declare
         myList test_list := test_list();
         myList2 test_list := test_list();
         sids ton_t := ton_t();
    begin
         for i in 1..10000 loop
              myList.extend; myList(myList.last) := test_obj(i, sysdate, to_char(i+2));
         end loop;
         -- save into the real table
         insert into test_table select * from table(cast (myList as test_list));
         dbms_output.put_line(chr(10) || 'copy ''mylist'' to ''mylist2'' by streaming via table function...');
         select test_obj(a, b, c) bulk collect into myList2
         from table(test_pkg.TF(CURSOR(select /*+ parallel(tab,10) */ * from table(cast (myList as test_list)) tab)));
         dbms_output.put_line('... saved #' || myList2.count || ' records');
         select distinct(tab.a) bulk collect into sids from table(cast (myList2 as test_list)) tab;
         dbms_output.put_line('worker thread''s sid list:');
         for i in sids.first..sids.last loop
              dbms_output.put_line('sid #' || sids(i));
         end loop;
         dbms_output.put_line(chr(10) || 'copy physical ''test_table'' to ''mylist2'' by streaming via table function:');
         select test_obj(a, b, c) bulk collect into myList2
         from table(test_pkg.TF(CURSOR(select /*+ parallel(tab,10) */ * from test_table tab)));
         dbms_output.put_line('... saved #' || myList2.count || ' records');
         select distinct(tab.a) bulk collect into sids from table(cast (myList2 as test_list)) tab;
         dbms_output.put_line('worker thread''s sid list:');
         for i in sids.first..sids.last loop
              dbms_output.put_line('sid #' || sids(i));
         end loop;
    end;
    -------------------- snap ---------------------------------------------
    Here's the output:
    -------------------- snip ---------------------------------------------
    copy 'mylist' to 'mylist2' by streaming via table function...
    test_pkg.TF( sid => '98' ): enter
    test_pkg.TF( sid => '98' ): exit, piped #10000 records
    ... saved #10000 records
    worker thread's sid list:
    sid #98 -- ONLY A SINGLE SID HERE!
    copy physical 'test_table' to 'mylist2' by streaming via table function:
    ... saved #10000 records
    worker thread's sid list:
    sid #128 -- A LIST OF SIDS HERE!
    sid #141
    sid #85
    sid #125
    sid #254
    sid #101
    sid #124
    sid #109
    sid #142
    sid #92
    PL/SQL procedure successfully completed.
    -------------------- snap ---------------------------------------------
    I posted it to newsgroup comp.databases.oracle.server.
    (summary: "10g: parallel pipelined table functions with cursor selecting from table(cast(SQL collection)) doesn't work ")
    But i didn't get a response.
    There i also wrote some background information about my application:
    -------------------- snip ---------------------------------------------
    My application has a #2 steps/stages data selection.
    A 1st select for minimal context base data
    - mainly to evaluate for due driving data records.
    And a 2nd select for all the "real" data to process a context
    (joining much more other tables here, which i don't want to do for non-due records).
    So it's doing stage #1 select first, then stage #2 select - based on stage #1 results - next.
    The first implementation of the application did the stage #1 select in the main session of the pl/sql code.
    And for the stage #2 select there was done a dispatch to multiple parallel table functions (in multiple worker sessions) for the "real work".
    That worked.
    However there was a flaw:
    Between records from stage #1 selection and records from stage #2 selection there is a 1:n relation (via key / foreign key relation).
    Means, for #1 resulting record from stage #1 selection, there are #x records from stage #2 selection.
    That forced me to use "cluster curStage2 by (theKey)".
    Because the worker sessions need to evaluate the all-over status for a context of #1 record from stage #1 and #x records from stage #2
    (so it needs to have #x records of stage #2 together).
    This then resulted in delay for starting up the worker sessions (i didn't find a way to get rid of this).
    So i wanted to shift the invocation of the worker sessions to the stage #1 selection.
    Then i don't need the "cluster curStage2 by (theKey)" anymore!
    But: i also need to do an update of the primary driving data!
    So the stage #1 select is a 'select ... for update ...'.
    But you can't use such in CURSOR for table functions (which i can understand, why it's not possible).
    So i have to do my stage #1 selection in two steps:
    1. 'select for update' by main session and collect result in SQL collection.
    2. pass collected data to parallel table functions
    And for 2. i recognized, that it doesn't start up multiple parallel table function instances.
    As a work-around
    - if it's just not possible to start multiple parallel pipelined table functions for dispatching from 'select * from TABLE(CAST(... as ...))' -
    i need to select again on the base tables - driven by the SQL collection data.
    But before i do so, i wanted to verify, if it's really not possible.
    Maybe i just miss a special oracle hint or whatever you can get "out of another box" :-)
    -------------------- snap ---------------------------------------------
    - many thanks!
    rgds,
    Frank

  • Group and sort in webi report

    I have a requirement to group and sort in a report. Group should be based on id, sort based on time. Time sort should be the priority. Meaning, first criteria to sort is time, but if the id is repeated, time should be sorted for that id.
    e.g, If I have ids A,B,C and values are such that A - 9:15 AM, B - 9:00 AM, A - 10:00 AM, C - 9:30 AM.
    Requirement is as below
    B - 9:00 AM
    A - 9:15 AM
    A - 10:00 AM
    C - 9:30 AM
    If I apply sort on time without group on id, I am getting data in the below manner which is not correct.
    B - 9:00 AM
    A - 9:15 AM
    C - 9:30 AM
    A - 10:00 AM
    If I apply group first, I am not able to apply sort. Since the requirement is to show the least time first.
    Please advice.

    use the variable
    =Min([Time]) In ([ID])
    to sort. Then hide the column by reducing the width and making the font and background color as white.

  • Group by sort order and display accordingly

    I have two groups - primary sort order and a secondary sort order in my report, formula for both follows:
    If {?Sort Order}='1' then {PRODUCT_CUSTOMER_MNT_V.CUSTOMER_NAME}
    else if {?Sort Order}='2' then {PRODUCT_CUSTOMER_MNT_V.PRODUCT_ID}
    else if {?Sort Order}='3' then {PRODUCT_CUSTOMER_MNT_V.CUST_REVISION_LEVEL}
    else if {?Sort Order}='4' then {PRODUCT_CUSTOMER_MNT_V.CMS_UD36}
    else if {?Sort Order}='5' then {PRODUCT_CUSTOMER_MNT_V.CMS_UD38}
    else if {?Sort Order}='6' then totext(year({PRODUCT_CUSTOMER_MNT_V.PURCHASE_DATE}),0,"")"/"
    right("0" + totext(month({PRODUCT_CUSTOMER_MNT_V.PURCHASE_DATE}),0,""),2)"/"
    right("0" + totext(day({PRODUCT_CUSTOMER_MNT_V.PURCHASE_DATE}),0,""),2)
    Groups are suppressed and fields are placed in the detail the line.  I have a request to group by Customer name with selected product ID's listed or vice versa.   My quandry is how do I accomodate the descriptive fields in the page header since the user can select any number of combinations using the sort order parameter.  Sure, right now they are only looking at customer and product ID but let's face it, that requirement could change in the future.  Seems simple enough but it's been awhile since I've touched reports and my brain is fuzzy.  Is what I'm trying to do possible?   Crystal XI (11.0.0.1282)

    I was overthinking the problem.  The report was already sorting on customer or product based on user selection.  I placed the customer ID/Name field and the Product ID field into group one and checked the underlay following section box in section expert.  This is will work fine for our purposes.

  • Table Operator In PL/SQL

    Sir,
    This is srinivas from India
    Recently I started working with Objects in Pl/SQL
    I am facing problem with table operator in pl/sql
    my Query is
    Select s.rollno,s.Name,column_value from student s,table(marks)
    above query working fine in at SQL Prompt
    but the same thing if I am trying to use at Cursors in PL/SQL it is giving error
    please suggest me how to use Table operator in PL/SQL
    student
    srinivas

    I suggest you post your problem to the Products->Database->SQL/PLSQL discussion Forum.
    This Forum is meant for the Apple Macintosh OS.

  • Oracle 10g group by sorting

    Hello friends
    Pls refere to my previous thread where we have discussed on sorting oprtion of Adding order by whereever group by is applicable
    ORACLE 10G group by sorting Suggestion rqd
    Read?
    Then come to my point
    if there is multiple columns for the group by then if we want to include order by clause, same number of columns has to be included in the order by also.
    i dont think it is so
    example'
    SELECT SUM(QTY1),SUM(QTY2), PARTNO, PART_DESC
    from part_sen
    group by partno, part_desc
    order by partno, part_desc
    qty1 qty2 partno partdesc
    70     101     I001     BRAKE SHOE
    56     54     I002     HORN
    30     30     I003     GEAR
    15     5     I004     DOOR
    5     5     I007     MOTOR GEAR
    10     15     I008     ANCILLARY
    10     15     I009     Window
    so in order by clause we can include only the first column.. that is partno
    SELECT SUM(QTY1),SUM(QTY2), PARTNO, PART_DESC
    from part_sen
    group by partno, part_desc
    order by partno
    Same result i get.
    Pls give your suggestion
    s

    ALex,
    SELECT SUM(QTY1),SUM(QTY2), PARTNO, PART_DESC
    from part_sen
    group by partno, part_desc
    70     101     I001     BRAKE SHOE
    56     54     I002     HORN
    30     30     I003     GEAR
    15     5     I004     DOOR
    5     5     I007     MOTOR GEAR
    10     15     I008     ZLLADER
    10     15     I008     OCTLADER
    10     15     I008     ANCILLARY
    10     15     I008     BALLLADER
    10     15     I009     Window
    SELECT SUM(QTY1),SUM(QTY2), PARTNO, PART_DESC
    from part_sen
    group by partno, part_desc
    order by partno
    70     101     I001     BRAKE SHOE
    56     54     I002     HORN
    30     30     I003     GEAR
    15     5     I004     DOOR
    5     5     I007     MOTOR GEAR
    10     15     I008     ANCILLARY
    10     15     I008     BALLLADER
    10     15     I008     OCTLADER
    10     15     I008     ZLLADER
    without ordering the second column part_desc it is properly ordered how?
    so adding order by partno is same as order by partno,part_desc
    Pls reply
    S

  • Use Parameter to choose Group and Sort options

    I've got a report that gets used for several different puposes, and needs to be grouped or sorted differently each time.  How can I use a parameter to let the user choose the group and sort options at runtime?
    I'm using CR2008, and SAP B1 2005.  The various grouping options I want to offer include SKU, Vendor and Description, and sorting within those Groups by SKU or Description.
    I'm a newbie with CR, so detailed instructions would be really helpful.

    You can create a report using parameter field. Follow these steps
    -- Create new parameter in the field explorer window
    -- The parameter shouls be static and enter all the field names on which you want to create in the values option
    -- Now create a formula like this
    if {?Parameter}="fieldname1" then
    else
    if {?Parameter}="fieldname2" then
    else
    -- Now insert new group and select this formula
    -- Now the group will change according to the parameter selected
    Please note that if you have different data types of fields you must need to convert totext()
    as If condition will allow only one data type output.
    Also when you insert any group by default the data is sorted on grouped field. If you want to sort on another field then you need to insert a summary field on that and go to report>group sort expert>select the field-->All based on the summary inserted.
    Hope this helps!
    Raghavendra

Maybe you are looking for