Group by in PL/SQL

Hi,
Begin
SELECT
PR.VENDOR_CODE INTO PR_VENDORE_CODE_V,
SUM(PRD.rejected_qty) INTO PR_REJECTED_QTY_V
FROM
PURCHASE_RETURN PR,
PURCHASE_RETURN_DETAIL PRD
WHERE
PR.PR_NO = PRD.PR_NO AND
PR.COMPANY_CODE = company_code_fk_V AND
PR.PR_NO = purchae_return_no_FK_v
GROUP BY
PR_VENDORE_CODE_V;
End;
it gives me an error groupby function not allowed here.
pls help

Thanks !
Opops i again got an error.
(1): PLS-00323: subprogram or cursor 'PRO_EXCISE_RG23A_PART1_N' is declared in a package specification and must be defined in the package body
SPEC
PACKAGE PACK_EXCISE_REGISTER_ENTRIES
AS PROCEDURE PRO_EXCISE_RG23A_PART1_N (user_id_fk_V IN EXCISE_RG23A_PART1_N.user_id_fk%TYPE,
company_code_fk_V IN EXCISE_RG23A_PART1_N.company_code_fk%TYPE ,
gpi_bill_entry_no_v IN EXCISE_RG23A_PART1_N.gpi_bill_entry_no%TYPE,
gpi_bill_entry_date_v IN EXCISE_RG23A_PART1_N.gpi_bill_entry_date%TYPE,
qty_issue_slip_v IN EXCISE_RG23A_PART1_N.qty_issue_slip%TYPE,
issue_slip_date_v IN EXCISE_RG23A_PART1_N.issue_slip_date%TYPE,
issue_slip_no_fk_v IN EXCISE_RG23A_PART1_N.issue_slip_no_fk%TYPE,
purchae_return_no_FK_v IN EXCISE_RG23A_PART1_N.purchae_return_no_FK%TYPE,
pr_vendor_code_fk_v IN EXCISE_RG23A_PART1_N.pr_vendor_code_fk%TYPE,
qty_purchase_return_v IN EXCISE_RG23A_PART1_N.qty_purchase_return%TYPE,
balance_qty_stock_v IN EXCISE_RG23A_PART1_N. BALANCE_QTY_STOCK%TYPE,
EXCISE_INSERT_TYPE_V VARCHAR2
END;
PACKAGE BODY
PACKAGE BODY PACK_EXCISE_REGISTER_ENTRIES AS
PROCEDURE PRO_EXCISE_RG23A_PART1_N( user_id_fk_V IN EXCISE_RG23A_PART1_N.user_id_fk%TYPE,
company_code_fk_V IN EXCISE_RG23A_PART1_N.company_code_fk%TYPE ,
/* GET MATERIAL RECEIPT(GRN) VALUES*/
--gpi_bill_entry_no_v is also used for domestic invoice as DOMESTIC NO
--also used for grn no
gpi_bill_entry_no_v IN EXCISE_RG23A_PART1_N.gpi_bill_entry_no%TYPE,
gpi_bill_entry_date_v IN EXCISE_RG23A_PART1_N.gpi_bill_entry_date%TYPE,
/* GET ISSUSE TO PRODUCTION VALUES*/
qty_issue_slip_v IN EXCISE_RG23A_PART1_N.qty_issue_slip%TYPE,
issue_slip_date_v IN EXCISE_RG23A_PART1_N.issue_slip_date%TYPE,
issue_slip_no_fk_v IN EXCISE_RG23A_PART1_N.issue_slip_no_fk%TYPE,
/* GET PURCHASE RETURN TO VENDORE VALUES*/
purchae_return_no_FK_v IN EXCISE_RG23A_PART1_N.purchae_return_no_FK%TYPE,
pr_vendor_code_fk_v IN EXCISE_RG23A_PART1_N.pr_vendor_code_fk%TYPE,
qty_purchase_return_v IN EXCISE_RG23A_PART1_N.qty_purchase_return%TYPE,
/*RECEIVE TYPE FOR RG23 ENTRIES*/
EXCISE_INSERT_TYPE_V VARCHAR2)
IS
EXCISE_MAXCODE_V NUMBER;
EXCISE_SL_NO_V NUMBER;
/*USED FOR MATERIAL RECEIPT*/
RECEIPT_ID_V VARCHAR2(50);
RECEIPT_DATE_V DATE;
VENDORE_CODE_V VARCHAR2(50);
ITEM_DESC_V VARCHAR2(50);
ITEM_QTY_UOM_V VARCHAR2(50);
/*USED FOR DOMESTIC INVOICE*/
DOMESTIC_TARIFF_CODE_V VARCHAR2(20);
DOMESTIC_EXCISE_DUTY_V NUMBER;
DOMESTIC_CESS_DUTY_V NUMBER;
/*USED FOR PURCHASE RETURN TO VENDORE*/
PR_VENDORE_CODE_V VARCHAR2(20);
PR_REJECTED_QTY_V NUMBER;
BEGIN
IF EXCISE_INSERT_TYPE_V ='GRN' THEN
DECLARE
/*Create Cursor to get Material Receipt(GRN) Values*/
CURSOR GET_GRN_RECEIPT_CUR IS
SELECT
RM.receipt_id,
RM.receipt_date,
VM.CODE,
IMDESC.ITEM_DESC,
SUM(RD.received_qty) || ' ' || UM.UOM_NAME AS ITEM_QTY_UOM
FROM
RECEIPT_MASTER RM,
RECEIPT_DETAIL RD,
VENDOR_MASTER VM,
uom_master UM,
SELECT
RD.RECEIPT_ID,
IM.CODE,
CASE WHEN RD.HEAT_NO IS NOT NULL THEN 'STEEL' ELSE IM.NAME END AS ITEM_DESC
FROM
RECEIPT_DETAIL RD,
ITEM_MASTER IM
WHERE
IM.CODE = RD.ITEM_CODE
) IMDESC
WHERE
RM.receipt_id = RD.receipt_id AND
RM.vendor_id = VM.code AND
RM.company_code = company_code_fk_V AND
IMDESC.receipt_id = RM.receipt_id AND
UM.UOM_CODE = RD.PO_UNIT AND
RM.RECEIPT_ID = gpi_bill_entry_no_v
GROUP BY
RM.receipt_id, RM.receipt_date,
VM.CODE, VM.EXCISE_range,
VM.excise_collectorate, IMDESC.ITEM_DESC, UM.UOM_NAME;
BEGIN
SELECT NVL(MAX(sl_no),0) +1 INTO EXCISE_SL_NO_V FROM EXCISE_RG23A_PART1_N ;
/*Check to see if cursor is already open. If not, open it. */
IF NOT GET_GRN_RECEIPT_CUR%ISOPEN THEN
OPEN GET_GRN_RECEIPT_CUR;
END IF;
LOOP
/* Retrieve each row of the result of the above query into PL/SQL variables: */
FETCH GET_GRN_RECEIPT_CUR INTO RECEIPT_ID_V, RECEIPT_DATE_V, VENDORE_CODE_V,
ITEM_DESC_V, ITEM_QTY_UOM_V;
/* Insert into Excise Register 23A Part 1 AGAINST GRN ENTRY(S)*/
INSERT INTO EXCISE_RG23A_PART1_N
(user_id_fk,
transaction_date,
company_code_fk,
sl_no,
rg23ap1_id_pk,
rg23ap1_date,
receive_input_desc,
qty_received_in_units,
gpi_bill_entry_no,
gpi_bill_entry_date,
gpi_vendor_code_fk,
balance_qty_stock,
entry_mode)
VALUES
(user_id_fk_V,
SYSDATE,
company_code_FK_V,
EXCISE_SL_NO_V,
(SELECT NVL(MAX(rg23ap1_id_pk),0) +1 FROM EXCISE_RG23A_PART1_N),
SYSDATE,
ITEM_DESC_V,
ITEM_QTY_UOM_V,
RECEIPT_ID_V,
RECEIPT_DATE_V,
VENDORE_CODE_V,
NVL((SELECT balance_qty_stock FROM EXCISE_RG23A_PART1_N WHERE
rg23ap1_id_pk = (SELECT MAX(rg23ap1_id_pk) -1 FROM EXCISE_RG23A_PART1_N) - qty_received_in_units),0),
'GRN');
/* Finish entry(s) in Excise Register 23A Part 1 AGAINST GRN ENTRY(S)*/
END LOOP;
/* Free cursor used by the query */
CLOSE GET_GRN_RECEIPT_CUR;
/* Insert into Excise Register Part 2 AGAINST GRN ENTRY(S)*/
INSERT INTO EXCISE_RG23A_PART2_N(
user_id_fk,
transaction_date,
company_code_fk,
sl_no,
rg23ap2_date,
open_bal_bed,
open_bal_cess,
fca_bill_no,
fca_date,
fca_vendor_code_fk,
received_bed,
received_cess,
total_bed,
total_cess,
entry_mode)
VALUES(
user_id_fk_V,
SYSDATE,
company_code_FK_V,
(SELECT NVL(MAX(sl_no),0) FROM EXCISE_RG23A_PART1_N),
SYSDATE,
NVL((SELECT balance_bed FROM EXCISE_RG23A_PART2_N WHERE
sl_no = (SELECT MAX(sl_no) -1 FROM EXCISE_RG23A_PART2_N)),0),
NVL((SELECT balacne_cess FROM EXCISE_RG23A_PART2_N WHERE
sl_no = (SELECT MAX(sl_no) -1 FROM EXCISE_RG23A_PART2_N)),0),
gpi_bill_entry_no_v,
gpi_bill_entry_date_v,
(SELECT gpi_vendor_code_fk FROM EXCISE_RG23A_PART1_N
WHERE sl_no = (SELECT NVL(MAX(rg23ap1_id_pk),0) FROM EXCISE_RG23A_PART1_N)),
(SELECT EXCISE_DUTY FROM RECEIPT_MASTER WHERE RECEIPT_ID = gpi_bill_entry_no_v),
(SELECT CESS_DUTY FROM RECEIPT_MASTER WHERE RECEIPT_ID = gpi_bill_entry_no_v),
(NVL((SELECT balance_bed FROM EXCISE_RG23A_PART2_N WHERE
sl_no = (SELECT MAX(sl_no) -1 FROM EXCISE_RG23A_PART2_N)),0) + (SELECT EXCISE_DUTY FROM RECEIPT_MASTER WHERE RECEIPT_ID = gpi_bill_entry_no_v)),
(NVL((SELECT balacne_cess FROM EXCISE_RG23A_PART2_N WHERE
sl_no = (SELECT MAX(sl_no) -1 FROM EXCISE_RG23A_PART2_N)),0) + (SELECT CESS_DUTY FROM RECEIPT_MASTER WHERE RECEIPT_ID = gpi_bill_entry_no_v)),
'GRN');
/* Finish entry(s) in Excise Register 23A Part 2 AGAINST GRN ENTRY(S)*/
END;
END IF;
IF EXCISE_INSERT_TYPE_V ='PRV' THEN
BEGIN
/*Create Select Statement to get Purchase Return to Vendor Values*/
SELECT PR.VENDOR_CODE, SUM(PRD.rejected_qty) INTO PR_VENDORE_CODE_V, PR_REJECTED_QTY_V
FROM
PURCHASE_RETURN PR,
PURCHASE_RETURN_DETAIL PRD
WHERE
PR.PR_NO = PRD.PR_NO AND
PR.COMPANY_CODE = company_code_fk_V AND
PR.PR_NO = purchae_return_no_FK_v;
/* Insert into Excise Register 23A part 1 AGAINST PURCHASE RETURN TO VENDORE*/
INSERT INTO EXCISE_RG23A_PART1_N(
user_id_fk,
transaction_date,
company_code_fk,
sl_no,
rg23ap1_id_pk,
rg23ap1_date,
purchae_return_no_fk,
pr_vendor_code_fk,
qty_purchase_return,
balance_qty_stock,
entry_mode)
VALUES(
user_id_fk_V,
SYSDATE,
company_code_FK_V,
EXCISE_SL_NO_V,
(SELECT NVL(MAX(rg23ap1_id_pk),0) +1 FROM EXCISE_RG23A_PART1_N),
SYSDATE,
purchae_return_no_FK_v,
PR_VENDORE_CODE_V,
PR_REJECTED_QTY_V,
NVL((SELECT balance_qty_stock FROM EXCISE_RG23A_PART1_N WHERE
rg23ap1_id_pk = (SELECT MAX(rg23ap1_id_pk) -1 FROM EXCISE_RG23A_PART1_N) - qty_received_in_units),0),
'PRN');
/* Finish entry(s) in Excise Register 23A Part 1 AGAINST PURCHASE RETURN TO VENDORE*/
END;
END IF;
IF EXCISE_INSERT_TYPE_V ='DI' THEN
BEGIN
/*GET EXCIE_DUTY FROM DOMESTIC INVOICE*/
SELECT chapterheading_code,
(ROUND(((di_m_bed_pc/100) * di_m_totalamount),2)),
ROUND((((di_m_bed_pc/100) * di_m_totalamount) * (di_m_cess_pc/100)),2)
INTO DOMESTIC_TARIFF_CODE_V, DOMESTIC_EXCISE_DUTY_V, DOMESTIC_CESS_DUTY_V
FROM
domesticinvoice_master
WHERE
DI_M_CODE= gpi_bill_entry_no_v;
/* Insert into Excise Register Part 2 AGAINST DOMESTIC INVOICE*/
INSERT INTO EXCISE_RG23A_PART2_N(
user_id_fk,
transaction_date,
company_code_fk,
open_bal_bed,
open_bal_cess,
tariff_head_code,
bed_debit,
cess_debit,
total_bed,
total_cess,
entry_mode)
VALUES(
user_id_fk_V,
SYSDATE,
company_code_FK_V,
NVL((SELECT balance_bed FROM EXCISE_RG23A_PART2_N WHERE
sl_no = (SELECT MAX(sl_no) -1 FROM EXCISE_RG23A_PART2_N)),0),
NVL((SELECT balacne_cess FROM EXCISE_RG23A_PART2_N WHERE
sl_no = (SELECT MAX(sl_no) -1 FROM EXCISE_RG23A_PART2_N)),0),
DOMESTIC_TARIFF_CODE_V,
DOMESTIC_EXCISE_DUTY_V,
DOMESTIC_CESS_DUTY_V,
(NVL((SELECT balance_bed FROM EXCISE_RG23A_PART2_N WHERE
sl_no = (SELECT MAX(sl_no) -1 FROM EXCISE_RG23A_PART2_N)),0) - DOMESTIC_EXCISE_DUTY_V),
(NVL((SELECT balacne_cess FROM EXCISE_RG23A_PART2_N WHERE
sl_no = (SELECT MAX(sl_no) -1 FROM EXCISE_RG23A_PART2_N)),0) - DOMESTIC_CESS_DUTY_V),
'DI');
/* Finish entry(s) in Excise Register 23A Part 2 AGAINST DOMESTIC INVOICE*/
END;
END IF;
--END;
END PRO_EXCISE_RG23A_PART1_N;
END PACK_EXCISE_REGISTER_ENTRIES;
-- End of DDL Script for Package Body FORGE.PACK_EXCISE_REGISTER_ENTRIES

Similar Messages

  • How to use group by in PL/SQL

    Can anyone give me a clue how to group rows using PL/SQL? I want to make a push button that groups a number of rows. When I run the form and push the button, I get the Oracle 01422 error. I am using one data block and, after pressing execute on the Oracle form in the web browser, I want to sort the rows using the group by clause as a pl sql trigger in a push button (with the WHEN BUTTON PRESSED trigger). I am new to Oracle Forms.

    I managed to use a cursor to access and display each row. I have to press the command button I created once for access of each row individually. I want to be able to push the button once, and populate each row with a record from my table. I am using the tabular format. Here is my code:
    DECLARE
         CURSOR email_message_cur
         IS
              SELECT sender, subject, body, date_time_sent
              FROM Email_Message
              ORDER BY sender;
    BEGIN
         OPEN email_message_cur;
         FETCH email_message_cur
         INTO :GROUP_EMAIL_MESSAGE.SENDER, :GROUP_EMAIL_MESSAGE.SUBJECT, :GROUP_EMAIL_MESSAGE.BODY, :GROUP_EMAIL_MESSAGE.DATE_TIME_SENT;
         WHILE email_message_cur%FOUND LOOP
              IF :GROUP_EMAIL_MESSAGE.SENDER IS NOT NULL THEN
                   CREATE_RECORD;
              END IF;
              FETCH email_message_cur INTO :GROUP_EMAIL_MESSAGE.SENDER, :GROUP_EMAIL_MESSAGE.SUBJECT, :GROUP_EMAIL_MESSAGE.BODY, :GROUP_EMAIL_MESSAGE.DATE_TIME_SENT;
         END LOOP;
         CLOSE email_message_cur;
    END;

  • How to pass HTML radio group value to an SQL query

    I need to display a radio group in Printer Friendly Mode so that when the value in the radio group changes the page is submitted and the report is updated to the new value.
    I can't use a standard APEX radio group item as it renders in disabled mode when the page is in printer friendly mode.
    I have therefore used a standard HTML radio group in a HTML region as follows:
    <div id="radio_bank" align="left" class="NonPrintable">
    <input type="radio" name="bank" value="Trial Bank"> Trial Bank
    <input type="radio" name="bank" value="Tissue Bank" checked> Tissue Bank
    <input type="radio" name="bank" value="Temporary Bank"> Temporary Bank
    <input type="radio" name="bank" value="All"> All
    </div>
    I have set up a dynamic action to submit the page on change event. This works but it navigates me to a "Page cannot be found " error page. I have an unconditional branch defined on the current page but this is ignored.
    Questions
    1) can a standard APEX radio group appear in Printer friendly mode? - This would solve my problem.
    2) how to submit the page using the above scenario to render the current page (dynamic action)
    3) how to capture the selected value of the radio group and pass it to SQL where clause
    thanks in advance
    PaulP

     

  • How to retrieve Min(startDate) and Max(endDate) for different groups of data? (sql server 2000)

    My sample dataset (below) contains 3 groups -- 'a', 'b', 'c'.  I need to retrieve the Min(startDate) and Max(EndDate) for each group so that the output looks something like this (date format not an issue):
    fk   minStart       maxEnd
    a    1/13/1985    12/31/2003
    b    2/14/1986    12/31/2003
    c    4/26/1987    12/31/2002
    What is the Tsql to perform this type of operation?  Note:  the actual data resides in a sql server 2000 DB.  If the Tsql is different between version 2000 and the later versions -- I would be grateful for both versions of the Tsql
    --I noticed that multiple lines of Insert values doesn't work in Sql Server 2000 -- this sample is in Sql Server 2008
    create table #tmp2(rowID int Identity(1,1), fk varchar(1), startDate datetime, endDate datetime)
    insert into #tmp2
    values
    ('a', '1/13/1985', '12/31/1999'),
    ('a', '3/17/1992', '12/31/1997'),
    ('a', '4/21/1987', '12/31/2003'),
    ('b', '2/14/1986', '12/31/2003'),
    ('b', '5/30/1993', '12/31/2001'),
    ('b', '6/15/1994', '12/31/2003'),
    ('b', '7/7/2001', '12/31/2003'),
    ('c', '4/26/1987', '12/31/1991'),
    ('c', '8/14/1992', '12/31/1998'),
    ('c', '9/10/1995', '12/31/2002'),
    ('c', '10/9/1996', '12/31/2000')
    Thanks
    Rich P

    Rich
    It is unclear what you are trying to achieve, you said that it is SQL Server 2000 but provide a sample data with SQL Server 2008 syntax
    Is it possible to use UNION ALL for your queries to make its one 
    select * from
    select * from #tmp2 t1 where exists
    (select * from (select top 1 * from #tmp2 t2 where t2.fk = t1.fk order by t2.startdate) x where x.rowID = t1.rowID)
    UNION ALL
    select * from #tmp2 t1 where exists
    (select * from (select top 1 * from #tmp2 t2 where t2.fk = t1.fk order by t2.Enddate desc) x where x.rowID = t1.rowID)
     as  der order by fk
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

  • Grouping Rules in PL/SQL Help needed

    Hi I have a requirement where I wan to group based on the below scenario
    I have a Table_A
    Table_A strcuture:
    create table table_a
    code number,
    name varchar2 (100),
    city varchar2 (100),
    dept varchar2 (100));;
    insert into table_a
    values
    1,'ABC','EA','A');
    insert into table_a
    values
    1,'ABC','EA1','A');
    insert into table_a
    values
    2,'BCD','EA2','A');
    insert into table_a
    values
    2,'ABC','EA3','A'');
    insert into table_a
    values
    3,'KBC','EA,'A');
    insert into table_a
    values
    3,'ABC','EA,'A');
    wan to group the above table data based on name,city,dept
    I wan the data  as
    1           ABC             EA1    A
                 BCD            EA2     A
    2           BCD            EA2     A
                 ABC            EA3     A
    3           KBC            EA      A
                 BCD            EA      A
    Kindly any help will be needful for me

    This is more of a presentation layer problem I would not handle it in SQL. For example if the presentation layer is SQL Plus you can use BREAK command, like this.
    SQL> select * from table_a;
          CODE NAME       CITY       DEPT
             1 ABC        EA         A
             1 ABC        EA1        A
             2 BCD        EA2        A
             2 ABC        EA3        A
             3 KBC        EA         A
             3 ABC        EA         A
    6 rows selected.
    SQL> break on code
    SQL>
    SQL> select * from table_a order by code;
          CODE NAME       CITY       DEPT
             1 ABC        EA         A
               ABC        EA1        A
             2 BCD        EA2        A
               ABC        EA3        A
             3 KBC        EA         A
               ABC        EA         A
    6 rows selected.
    But if you still wish to do it in SQL the right way is to use ROW_NUMBER like this.
    SQL> clear breaks
    breaks cleared
    SQL>
    SQL> select * from table_a;
          CODE NAME       CITY       DEPT
             1 ABC        EA         A
             1 ABC        EA1        A
             2 BCD        EA2        A
             2 ABC        EA3        A
             3 KBC        EA         A
             3 ABC        EA         A
    6 rows selected.
    SQL> select decode(rno, 1, code) code
      2       , name
      3       , city
      4       , dept
      5    from (
      6           select row_number() over(partition by code order by name) rno
      7                , t.*
      8             from table_a t
      9         )
    10  /
          CODE NAME       CITY       DEPT
             1 ABC        EA         A
               ABC        EA1        A
             2 ABC        EA3        A
               BCD        EA2        A
             3 ABC        EA         A
               KBC        EA         A
    6 rows selected.

  • Group by in a SQL statement

    I have this SQL Statement
    SELECT PTE.PLT_SHORT_NAME PLT_SHORT_NAME,
    COUNT ( * ) SEGMENTS,
    COUNT ( DECODE ( SUBSTR ( TE.EVAL_RESULT , 1 , 1 ) , 'Y' , 1 , NULL ) ) SEGMENTS_COMPLY,
    COUNT ( DECODE ( SUBSTR ( TE.EVAL_RESULT , 1 , 1 ) , 'N' , 1 , NULL ) ) SEGMENTS_NO_COMPLY,
    SUM ( DECODE ( SUBSTR ( TE.EVAL_RESULT , 1 , 1 ) , 'Y' , ( TE.ACTUAL_DURA - ( TE.EXPCT_DURA ) ) , 0 ) ) TIEMPO_GANADO,
    ( ( COUNT ( DECODE ( SUBSTR ( TE.EVAL_RESULT , 1 , 1 ) , 'Y' , 1 , NULL ) ) / COUNT ( * ) ) * 100 ) || '%' COMPLY_PERCENT,
    SUM ( DECODE ( SUBSTR ( TE.EVAL_RESULT , 1 , 1 ) , 'N' , ( TE.ACTUAL_DURA - ( TE.EXPCT_DURA ) ) , 0 ) ) TIEMPO_PERDIDO,
    ( SUM ( DECODE ( SUBSTR ( TE.EVAL_RESULT , 1 , 1 ) , 'Y' , ( TE.ACTUAL_DURA - ( TE.EXPCT_DURA ) ) , 0 ) ) + SUM ( DECODE ( SUBSTR ( TE.EVAL_RESULT , 1 , 1 ) , 'N' , ( TE.ACTUAL_DURA - ( TE.EXPCT_DURA ) ) , 0 ) ) ) DIFERENCIA
    FROM PLT_TRN_EVALS PTE,
    TRN_EVALS TE,
    TRN_EVENT_TIMES_HEADERS TETH
    WHERE ( /* CG$MDTU_QWC_START Q_1.PTE */
    (PTE.PLT_SHORT_NAME IS NOT NULL AND PTE.DELETED = 'N')
    /* CG$MDTU_QWC_END Q_1.PTE */
    ) AND
    ( /* CG$MDTU_QWC_START Q_1.TE */
    (TE.TYP = 'SEG' AND TE.DELETED = 'N')
    /* CG$MDTU_QWC_END Q_1.TE */
    ) AND
    PTE.TE_SEQ = TE.SEQ AND
    ( /* CG$MDTU_QWC_START Q_1.TETH */
    (TETH.DELETED = 'N' AND TETH.SCHED_DATE BETWEEN :P_DATE_FROM AND :P_DATE_TO)
    /* CG$MDTU_QWC_END Q_1.TETH */
    ) AND
    TE.TETH_SEQ = TETH.SEQ
    GROUP BY PTE.PLT_SHORT_NAME
    And I would like to know, how can I include the GROUP BY in order to generate

    I think your question got cut off. What are you trying to generate with this SQL? I should say in advance that Oracle Designer has very few places where you can enter a SELECT command directly. You can usually get it to generate what you need by choosing the correct Table Definition (or View Definition) usages, choosing the display columns you want, and adding WHERE clauses and GROUP BY columns.
    With something as complex as your Statement, I would probably consider creating a View, then use the View in modules.

  • Identifying and grouping consecutive rows in sql

    I have following data set:
    CREATE TABLE APPS.T1
      ROW_NUM               NUMBER,
      EFFECTIVE_START_DATE  DATE                    NOT NULL,
      EFFECTIVE_END_DATE    DATE                    NOT NULL,
      STATUS                VARCHAR2(30 BYTE)
    SET DEFINE OFF;
    Insert into APPS.T1
       (ROW_NUM, EFFECTIVE_START_DATE, EFFECTIVE_END_DATE, STATUS)
    Values
       (1, TO_DATE('07/01/2009 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('09/06/2009 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'VAC');
    Insert into APPS.T1
       (ROW_NUM, EFFECTIVE_START_DATE, EFFECTIVE_END_DATE, STATUS)
    Values
       (2, TO_DATE('03/20/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('03/31/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'VAC');
    Insert into APPS.T1
       (ROW_NUM, EFFECTIVE_START_DATE, EFFECTIVE_END_DATE, STATUS)
    Values
       (3, TO_DATE('08/06/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/22/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'VAC');
    Insert into APPS.T1
       (ROW_NUM, EFFECTIVE_START_DATE, EFFECTIVE_END_DATE, STATUS)
    Values
       (4, TO_DATE('08/23/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/26/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'VAC');
    Insert into APPS.T1
       (ROW_NUM, EFFECTIVE_START_DATE, EFFECTIVE_END_DATE, STATUS)
    Values
       (5, TO_DATE('08/27/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), TO_DATE('08/27/2011 00:00:00', 'MM/DD/YYYY HH24:MI:SS'), 'VAC');
    COMMIT;
    SELECT * FROM APPS.T1
       ROW_NUM EFFECTIVE EFFECTIVE STATUS                       
             1 01-JUL-09 06-SEP-09 VAC                          
             2 20-MAR-11 31-MAR-11 VAC                          
             3 06-AUG-11 22-AUG-11 VAC                          
             4 23-AUG-11 26-AUG-11 VAC                          
             5 27-AUG-11 27-AUG-11 VAC                          
    5 rows selected.My requirement was that row number 3, 4 and 5 be grouped and treated as a single vacation record such that
    effective_start_date = 06-AUG-2011 and
    effective_end_date = 27-AUG-2011
    For this I wrote a query:
    SELECT effective_start_date,
           effective_end_date,
           CASE
              WHEN LAG (effective_end_date, 1) OVER (ORDER BY row_num) + 1 = effective_start_date
                 THEN 0
              WHEN LEAD (effective_start_date, 1) OVER (ORDER BY row_num) - 1 = effective_end_date
                 THEN 0
              ELSE 1
           END row_num
      FROM (SELECT * FROM T1)Now the data returned looks like:
    EFFECTIVE EFFECTIVE    ROW_NUM
    01-JUL-09 06-SEP-09          1
    20-MAR-11 31-MAR-11          1
    06-AUG-11 22-AUG-11          0
    23-AUG-11 26-AUG-11          0
    27-AUG-11 27-AUG-11          0
    5 rows selected.Now I can easily use MIN(effective_start_date) and MAX(effective_start_date) group by ROW_NUM to achieve the desired results
    SELECT   MIN (effective_start_date) start_dt,
             MAX (effective_start_date) end_dt,
             row_num
        FROM (SELECT effective_start_date,
                     effective_end_date,
                     CASE
                        WHEN LAG (effective_end_date, 1) OVER (ORDER BY row_num) + 1 = effective_start_date
                           THEN 0
                        WHEN LEAD (effective_start_date, 1) OVER (ORDER BY row_num) - 1 = effective_end_date
                           THEN 0
                        ELSE 1
                     END row_num
                FROM (SELECT *
                        FROM t1))
    GROUP BY row_num
      HAVING row_num = 0
    UNION
    SELECT effective_start_date start_dt,
           effective_start_date end_dt,
           row_num
      FROM (SELECT effective_start_date,
                   effective_end_date,
                   CASE
                      WHEN LAG (effective_end_date, 1) OVER (ORDER BY row_num) + 1 = effective_start_date
                         THEN 0
                      WHEN LEAD (effective_start_date, 1) OVER (ORDER BY row_num) - 1 = effective_end_date
                         THEN 0
                      ELSE 1
                   END row_num
              FROM (SELECT *
                      FROM t1))
    WHERE row_num = 1
    START_DT  END_DT       ROW_NUM
    01-JUL-09 01-JUL-09          1
    20-MAR-11 20-MAR-11          1
    06-AUG-11 27-AUG-11          0
    3 rows selected.All done BUT the problem is that there may be several groups of consecutive rows like this. In that case each group should be identified distinctly for GROUP BY clause to work as expected.
    I want to assign a unique number to each occurence of such group.
    How can I achieve this? Any ideas?
    Regards,
    Faraz
    Edited by: faanwar on May 10, 2012 3:36 PM

    Well, actually, you'll need to tweak it a bit. something such as in :Scott@my11g SQL>l
      1  with t (id, dstart, dend, status)
      2  as (
      3       select 1,to_date('01-JUL-09','dd-MON-YY'),to_date('06-SEP-09','dd-MON-YY'),'VAC' from dual
      4       union all select 2,to_date('20-MAR-11','dd-MON-YY'),to_date('31-MAR-11','dd-MON-YY'),'VAC' from dual
      5       union all select 3,to_date('06-AUG-11','dd-MON-YY'),to_date('22-AUG-11','dd-MON-YY'),'VAC' from dual
      6       union all select 4,to_date('23-AUG-11','dd-MON-YY'),to_date('26-AUG-11','dd-MON-YY'),'VAC' from dual
      7       union all select 5,to_date('27-AUG-11','dd-MON-YY'),to_date('27-AUG-11','dd-MON-YY'),'VAC' from dual
      8  )
      9  ------ end of sample data ------
    10  select min(dstart) dstart, max(dend) dend, status, count(*) aggrows
    11  from (
    12       select
    13       id
    14            ,dstart
    15            ,dend
    16            ,status
    17            ,dend
    18                 -sum(dend-dstart) over (partition by status order by dstart)
    19                 -row_number() over (partition by status order by dstart) grp
    20       from t
    21  )
    22  group by grp, status
    23* order by grp, status
    Scott@my11g SQL>/
    DSTART              DEND                STA    AGGROWS
    01/07/2009 00:00:00 06/09/2009 00:00:00 VAC          1
    20/03/2011 00:00:00 31/03/2011 00:00:00 VAC          1
    06/08/2011 00:00:00 27/08/2011 00:00:00 VAC          3

  • Group by change the sql plan by adding "filter"

    The table is created by:
    SQL> create table t1 as select  1 a,rownum b, rownum c from dual connect by rownum<10000;
    Table created.
    SQL> create index t1_idx on t1 (a,b);
    Index created.
    SQL> exec dbms_stats.gather_table_stats(null,'T1',cascade=>true,estimate_percent=>1,no_invalidate=>true,degree=>4,block_sample => true,granularity => 'ALL');
    PL/SQL procedure successfully completed.After added group by, the access and filter appear in the plan, and they are exactly the same
    SQL> set autotrace trace explain
    SQL> select b,count(*) from t1 where a=1 and b between 10 and 200 group by b;
    Execution Plan
    Plan hash value: 1662069396
    | Id  | Operation            | Name   | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT     |        |   192 |  1344 |     2 |
    |   1 |  SORT GROUP BY NOSORT|        |   192 |  1344 |     2 |
    |*  2 |   INDEX RANGE SCAN   | T1_IDX |   192 |  1344 |     2 |
    Predicate Information (identified by operation id):
       2 - access("A"=1 AND "B">=10 AND "B"<=200)
           filter("A"=1 AND "B">=10 AND "B"<=200)                  ===> *why filter happens here?*
    Note
       - cpu costing is off (consider enabling it)Without group by, only access appears in the plan
    SQL> select * from  t1 where a=1 and b between 10 and 200 ;
    Execution Plan
    Plan hash value: 1720721055
    | Id  | Operation                   | Name   | Rows  | Bytes | Cost  |
    |   0 | SELECT STATEMENT            |        |   192 |  1920 |     3 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| T1     |   192 |  1920 |     3 |
    |*  2 |   INDEX RANGE SCAN          | T1_IDX |   192 |       |     2 |
    Predicate Information (identified by operation id):
       2 - access("A"=1 AND "B">=10 AND "B"<=200)
    Note
       - cpu costing is off (consider enabling it)

    What's your version ?
    No filter on 10.2.0.4 :
    SQL> select b,count(*) from t1 where a=1 and b between 10 and 200 group by b;
    Execution Plan
    Plan hash value: 1662069396
    | Id  | Operation            | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT     |        |   192 |  1344 |     2   (0)| 00:00:01 |
    |   1 |  SORT GROUP BY NOSORT|        |   192 |  1344 |     2   (0)| 00:00:01 |
    |*  2 |   INDEX RANGE SCAN   | T1_IDX |   192 |  1344 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("A"=1 AND "B">=10 AND "B"<=200)
    SQL> select * from v$version;
    BANNER
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    PL/SQL Release 10.2.0.4.0 - Production
    CORE    10.2.0.4.0      Production
    TNS for HPUX: Version 10.2.0.4.0 - Production
    NLSRTL Version 10.2.0.4.0 - ProductionNicolas.

  • Referencing Record Groups in a PL/SQL Library program unit

    I want to move a program unit into a PL/SQL Library. I know how to reference data items from the form, but how do I reference a record group? Here's the code sample:
    PROCEDURE pu_init_tree IS
    HTREE ITEM;
    V_IGNORE NUMBER;
    BEGIN
    HTREE := FIND_ITEM('CONTROL_TREE.MENU');
    V_IGNORE := POPULATE_GROUP('RG_USER_MENU_TREE');
    FTREE.SET_TREE_PROPERTY(HTREE, FTREE.RECORD_GROUP,'RG_USER_MENU_TREE');
    :CONTROL.Node_Selected := Ftree.Get_Tree_Node_Property('CONTROL_TREE.MENU', 1, Ftree.NODE_VALUE) ;
    END;
    Thanks much

    Hi,
    you can try adding parameters to your program unit:
    PROCEDURE pu_init_tree(your_item_name in varchar2, your_rec_group_name in varchar2) IS
    HTREE ITEM;
    V_IGNORE NUMBER;
    BEGIN
    HTREE := FIND_ITEM(your_item_name);
    V_IGNORE := POPULATE_GROUP(your_rec_group_name);
    FTREE.SET_TREE_PROPERTY(HTREE, FTREE.RECORD_GROUP,your_rec_group_name);
    :CONTROL.Node_Selected := Ftree.Get_Tree_Node_Property('CONTROL_TREE.MENU', 1, Ftree.NODE_VALUE) ;
    END;
    Regards,
    Hugo

  • Service account not inheriting AD group membership permissions on SQL Server

    I am adding Active Directory groups as logins and database users to our SQL Servers. A service account added to an AD group did not inherit the group permissions that the user accounts did. Can there be different attributes of service accounts that would
    prevent service accounts from inheriting the permissions of AD groups?
    Example: An AD Group AD_group contains a service account user, svc_account and a user account, user_account. AD_group is added to a SQL Server as a login. User_account can log in to SQL Server but svc_account cannot.

    SQL Server will use the information within the token used for authentication, so it may be possible that the service has a stale token (i.e. the token has not been refreshed or the service has not restarted) since you made the changes to the AD group.
    I would recommend using a tool such as ProcessExplorer (https://technet.microsoft.com/en-us/sysinternals/bb896653) to make sure the token for the process is showing the latest group
    memberships properly.
    I hope this helps,
    -Raul Garcia
       SQL Server Security
    This posting is provided "AS IS" with no warranties, and confers no rights.

  • Urgent= How to Group selected columns in sql query

    Hi,
    I need some urgent help on the following sql query. I 'm sure there is an easy way to do this but I'm stacked!Any help will be much appreciated!!
    I have a query to retrieve the following columns:
    I want the first 9 columns to be grouped together (not to be repeated) for any occurence of the last 3 columns (abs.ABSENCE_START_DATE,abs.ABSENCE_END_DATE, abs.DAYS_TAKEN DAYS_TAKEN_analysis)
    SELECT DISTINCT
    sum.employee_number ,
    sum.EMPLOYEE_NAME,
    sum.EMAIL_ADDRESS,
    sum.ORGANIZATION ,
    sum.BCEBF ,
    sum.ALDE ,
    sum.CURYRREMDAYS ,
    sum.DAYS_TAKEN ,
    sum.REMBCE ,
    abs.ABSENCE_START_DATE
    abs.ABSENCE_END_DATE,
    abs.DAYS_TAKEN DAYS_TAKEN_analysis
    --TO_CHAR(TO_CHAR(abs.ABSENCE_START_DATE)||' '||TO_CHAR(abs.ABSENCE_END_DATE)||' '||TO_CHAR(abs.DAYS_TAKEN)) DAYS_TAKEN_ANAL
    FROM
    HB_V_ANNUAL_LEAVE_SUMMARY_REP SUM,
    HB_V_AN_LEAV_DAYS_TAKEN_REP ABS
    WHERE
    sum.employee_number = abs.EMPLOYEE_NUMBER
    ORDER BY
    sum.employee_number ,
    sum.EMPLOYEE_NAME,
    sum.EMAIL_ADDRESS,
    sum.ORGANIZATION ,
    sum.BCEBF ,
    sum.ALDE ,
    sum.CURYRREMDAYS ,
    sum.DAYS_TAKEN ,
    sum.REMBCE
    Any feedback/help on how to do this will be highly appreciated.
    Thanks a lot
    Elena

    Please help!!
    I used the break command to group columns that I do not want to repeat in my query output. When I run the query without formatting is working. But when I put all formatting to produce the required output I dont get the result I want.
    Below is the exact sql query I use:
    <<
    SET TERMOUT OFF
    SET ECHO OFF
    SET ARRAY 35
    SET HEA OFF
    SET FEEDBACK OFF
    SET PAGES 2000
    col beginLINE format A100
    col winsecidLINE format A100
    col placeLINE format A100
    COL LINEempty1 format A100
    COL LINEempty2 format A100
    COL LINEempty3 format A100
    COL LINEempty4 format A100
    COL LINEempty5 format A100
    COL LINEempty6 format A100
    COL LINEempty7 format A100
    COL LINEempty8 format A100
    COL LINEempty9 format A100
    COL LINEempty10 format A100
    col LINECOLempty format A100
    col receiverLINE FORMAT A100
    COL EMP_EMAIL_ADDRESS FORMAT A100
    COL LINEHEADER FORMAT A100
    COL unitsLINE FORMAT A100
    COL lmLINE FORMAT A100
    COL INTITLE FORMAT A100
    COL LINECOL1 FORMAT A100
    COL CIF FORMAT A100
    COL EMPLOYEE_NAME FORMAT A100
    COL ORGANIZATION FORMAT A100
    COL LINECOL2 FORMAT A100
    COL ALHEADER FORMAT A100
    col LINECOL3 FORMAT A100
    col BCEBF FORMAT A100
    col ALDE FORMAT A100
    COL CURYRREMDAYS FORMAT A100
    COL DAYS_TAKEN FORMAT A100
    col LINECOL4 FORMAT A100
    COL REMBCE FORMAT A100
    col LINECOL5 FORMAT A100
    col LINECOL6 FORMAT A100
    col ALHEADER2 FORMAT A100
    col LINECOL7 FORMAT A100
    col endLINE FORMAT A100
    break on beginLINE on winsecidLINE on placeLINE on LINEempty1 ON LINEempty2 ON LINEempty3 ON LINEempty4 ON LINEempty5 ON LINEempty6 ON LINEempty7 ON LINEempty8 ON LINEempty9 ON LINEempty10 on receiverLINE on EMP_EMAIL_ADDRESS on LINEHEADER on unitsLINE on lmLINE on INTITLE on LINECOL1 on CIF on EMPLOYEE_NAME on ORGANIZATION on LINECOL2 on ALHEADER on LINECOL3 on BCEBF on ALDE on CURYRREMDAYS on DAYS_TAKEN on LINECOL4 on REMBCE on LINECOL5 on LINECOL6 on ALHEADER2 on LINECOL7 ON LINEempty11 ON endREPORT on endLINE
    SPOOL C:\FORMATout.txt
    SELECT
    '{{begin}} '||chr(10) beginLINE,
    '{{winsecid 999999}} '||chr(10) winsecidLINE,
    '{{place rbsemail.tif 0 0}} '||chr(10) placeLINE,
    ' '||chr(10) LINEempty1,
    ' '||chr(10) LINEempty2,
    ' '||chr(10) LINEempty3,
    ' '||chr(10) LINEempty4,
    ' '||chr(10) LINEempty5,
    ' '||chr(10) LINEempty6,
    ' '||chr(10) LINEempty7,
    ' '||chr(10) LINEempty8,
    ' '||chr(10) LINEempty9,
    ' '||chr(10) LINEempty10,
    '{{from [email protected]}} '||chr(10) receiverLINE,
    '{{fax '|| EMAIL_ADDRESS||' }} '||chr(10) EMP_EMAIL_ADDRESS,
    '{{Subject Annual Leave Summary Report as at '||sysdate||' }} '||chr(10) LINEHEADER,
    '{{units cm}} '||chr(10) unitsLINE,
    '{{lm 2.0}} '||chr(10) lmLINE,
    'ANNUAL LEAVE SUMMARY REPORT AS AT '||sysdate INTITLE,
    '---------------------------------------------------------------------' LINECOL1,
    'CIF: '||CIF CIF,
    'EMPLOYEE NAME: '||EMPLOYEE_NAME EMPLOYEE_NAME,
    'DEPARTMENT DETAILS: '||ORGANIZATION ORGANIZATION,
    '---------------------------------------------------------------------' LINECOL2,
    'ANNUAL LEAVE DETAILS:' ALHEADER,
    '---------------------------------------------------------------------' LINECOL3,
    'BALANCE B/F FROM PREVIOUS YEAR: '||BCEBF BCEBF,
    'DAYS ENTITLED FOR THE CURRENT YEAR: '||ALDE ALDE,
    'CURRENT YEAR REMAINING DAYS: '||CURYRREMDAYS CURYRREMDAYS,
    'DAYS TAKEN FOR THE CURRENT YEAR: '||DAYS_TAKEN DAYS_TAKEN,
    '---------------------------------------------------------------------' LINECOL4,
    'REMAINING BALANCE: '||REMBCE REMBCE,
    '---------------------------------------------------------------------' LINECOL5,
    '---------------------------------------------------------------------' LINECOL6,
    'ANNUAL LEAVE DAYS TAKEN ANALYSIS FOR THE CURRENT YEAR:' ALHEADER2,
    '---------------------------------------------------------------------' LINECOL7,
    TO_CHAR('START DATE: '||ABSENCE_START_DATE||' '||'END DATE: '||ABSENCE_END_DATE||' '||'DAYS TAKEN : '||DAYS_TAKEN_ANAL) AL_DAYS_ANAL,
    ' '||chr(10) LINEempty11,
    '-- End of Report -- '||chr(10) endREPORT,
    '{{end}} '||chr(10) endLINE
    FROM HB_V_AN_LEAV_SUM_DAYSTAKEN_REP
    WHERE CIF IN ('098033','098024')
    ORDER BY
    beginLINE ,
    winsecidLINE,
    placeLINE ,
    LINEempty1,
    LINEempty2,
    LINEempty3,
    LINEempty4,
    LINEempty5,
    LINEempty6,
    LINEempty7,
    LINEempty8,
    LINEempty9,
    LINEempty10,
    receiverLINE,
    EMP_EMAIL_ADDRESS,
    LINEHEADER ,
    unitsLINE ,
    lmLINE ,
    INTITLE ,
    LINECOL1,
    CIF ,
    EMPLOYEE_NAME ,
    ORGANIZATION ,
    LINECOL2 ,
    ALHEADER ,
    LINECOL3,
    BCEBF ,
    ALDE ,
    CURYRREMDAYS ,
    DAYS_TAKEN ,
    LINECOL4 ,
    REMBCE ,
    LINECOL5 ,
    LINECOL6 ,
    ALHEADER2 ,
    LINECOL7 ,
    LINEempty11,
    endREPORT,
    endLINE
    spool off
    >>
    The required output I want to get is:
    <<
    {{begin}}
    {{winsecid 750612}}
    {{place rbsemail.tif 0 0}}
    {{from [email protected]}}
    {{fax [email protected] }}
    {{Subject Annual Leave Summary Report as at 04-APR-08 }}
    {{units cm}}
    {{lm 2.0}}
    ANNUAL LEAVE SUMMARY REPORT AS AT 04-APR-08
    CIF: 098024
    EMPLOYEE NAME: Christou Christos Panteli
    DEPARTMENT DETAILS: 003-031-010-314-03140-Special Projects
    ANNUAL LEAVE DETAILS:
    BALANCE B/F FROM PREVIOUS YEAR: 9
    DAYS ENTITLED FOR THE CURRENT YEAR: 27
    CURRENT YEAR REMAINING DAYS: 24
    DAYS TAKEN FOR THE CURRENT YEAR: -3
    REMAINING BALANCE: 33
    ANNUAL LEAVE DAYS TAKEN ANALYSIS FOR THE CURRENT YEAR:
    START DATE: 04-JAN-08 END DATE: 04-JAN-08 DAYS TAKEN : 1
    START DATE: 24-JAN-08 END DATE: 24-JAN-08 DAYS TAKEN : 1
    START DATE: 20-FEB-08 END DATE: 20-FEB-08 DAYS TAKEN : 1
    -- End of Report --
    {{end}}
    {{begin}}
    {{winsecid 750612}}
    {{place rbsemail.tif 0 0}}
    {{from [email protected]}}
    {{fax [email protected]}}
    {{Subject Annual Leave Summary Report as at 04-APR-08 }}
    {{units cm}}
    {{lm 2.0}}
    ANNUAL LEAVE SUMMARY REPORT AS AT 04-APR-08
    CIF: 098033
    EMPLOYEE NAME: Demetriou Elena Steliou
    DEPARTMENT DETAILS: 003-031-010-314-03140-Special Projects
    ANNUAL LEAVE DETAILS:
    BALANCE B/F FROM PREVIOUS YEAR: 15
    DAYS ENTITLED FOR THE CURRENT YEAR: 27
    CURRENT YEAR REMAINING DAYS: 25
    DAYS TAKEN FOR THE CURRENT YEAR: -2
    REMAINING BALANCE: 40
    ANNUAL LEAVE DAYS TAKEN ANALYSIS FOR THE CURRENT YEAR:
    START DATE: 15-JAN-08 END DATE: 15-JAN-08 DAYS TAKEN : 1
    START DATE: 24-MAR-08 END DATE: 24-MAR-08 DAYS TAKEN : 1
    -- End of Report --
    {{end}}
    >>
    However the actual output we get from the above query is as follows:
    <<
    {{begin}}
    {{winsecid 750612}}
    {{place rbsemail.tif 0 0}}
    {{from [email protected]}}
    {{fax [email protected] }}
    {{Subject Annual Leave Summary Report as at 04-APR-08 }}
    {{units cm}}
    {{lm 2.0}}
    ANNUAL LEAVE SUMMARY REPORT AS AT 04-APR-08
    CIF: 098024
    EMPLOYEE NAME: Christou Christos Panteli
    DEPARTMENT DETAILS: 003-031-010-314-03140-Special Projects
    ANNUAL LEAVE DETAILS:
    BALANCE B/F FROM PREVIOUS YEAR: 9
    DAYS ENTITLED FOR THE CURRENT YEAR: 27
    CURRENT YEAR REMAINING DAYS: 24
    DAYS TAKEN FOR THE CURRENT YEAR: -3
    REMAINING BALANCE: 33
    ANNUAL LEAVE DAYS TAKEN ANALYSIS FOR THE CURRENT YEAR:
    START DATE: 04-JAN-08 END DATE: 04-JAN-08 DAYS TAKEN : 1
    -- End of Report --
    {{end}}
    START DATE: 24-JAN-08 END DATE: 24-JAN-08 DAYS TAKEN : 1
    START DATE: 20-FEB-08 END DATE: 20-FEB-08 DAYS TAKEN : 1
    {{fax [email protected] }}
    {{Subject Annual Leave Summary Report as at 04-APR-08 }}
    {{units cm}}
    {{lm 2.0}}
    ANNUAL LEAVE SUMMARY REPORT AS AT 04-APR-08
    CIF: 098033
    EMPLOYEE NAME: Demetriou Elena Steliou
    DEPARTMENT DETAILS: 003-031-010-314-03140-Special Projects
    ANNUAL LEAVE DETAILS:
    BALANCE B/F FROM PREVIOUS YEAR: 15
    DAYS ENTITLED FOR THE CURRENT YEAR: 27
    CURRENT YEAR REMAINING DAYS: 25
    DAYS TAKEN FOR THE CURRENT YEAR: -2
    REMAINING BALANCE: 40
    ANNUAL LEAVE DAYS TAKEN ANALYSIS FOR THE CURRENT YEAR:
    START DATE: 15-JAN-08 END DATE: 15-JAN-08 DAYS TAKEN : 1
    -- End of Report --
    {{end}}
    START DATE: 24-MAR-08 END DATE: 24-MAR-08 DAYS TAKEN : 1
    >>
    IF ANYONE CAN HELP ON THIS I WOULD REALLY APPRECIATE IT!
    THANKS A LOT!
    Best regards,
    Elena

  • GROUP BY+COUNT+SUM SQL

    Hi,
    I have a table, it has 2 colunms, ( name,number)
    name number
    B1 7
    B1 7
    B1 28
    B1 28
    B1 28
    B2 7
    B2 28
    B3 7
    I want to see below
    number
    name sum 7sum 28sum
    B1 5 2 3
    B2 2 1 1
    B3 . . .
    CAN YOU HELP ME
    THANK YOU VERY MUCH FOR HELP

    Like this?
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select 'B1' as name, 7 as num from dual union all
      2             select 'B1', 7 from dual union all
      3             select 'B1', 28 from dual union all
      4             select 'B1', 28 from dual union all
      5             select 'B1', 28 from dual union all
      6             select 'B2', 7 from dual union all
      7             select 'B2', 28 from dual union all
      8             select 'B3', 7 from dual)
      9  --
    10  -- end of test data - use query below
    11  --
    12  select name
    13        ,count(*)
    14        ,sum(decode(num,7,1,0)) as sum7
    15        ,sum(decode(num,28,1,0)) as sum28
    16  from t
    17  group by name
    18* order by 1
    SQL> /
    NA   COUNT(*)       SUM7      SUM28
    B1          5          2          3
    B2          2          1          1
    B3          1          1          0

  • When to user Availability Group versus traditional Clustered SQL Server

    Hi...
    I'm trying to get my arms around when to use an SQL Server 2014 Availability Group. Here are the characteristics about my platform:
    2 physical servers (Windows Server 2012 / SQL Server 2014)
    Both servers connected to same LAN
    External SAN storage connected DIRECTLY to each physical server via fibr3-channel. (No fibre-channel switch)
    Database resides on SAN storage.
    I've set up a failover cluster between the 2 physical servers.
    I've created a high availability group with a Primary/Secondary and synchronization.
    Both Primary/Secondary are green and show synchronized. The concern I have is that the Primary says Synchronizing (No Data Loss) and the Secondary says Not Synchronizing (Data Loss). When I use the Failover Wizard to failover, it tells me that I will have
    data loss on the Secondary.
    So my questions are these, do you need more than one Secondary node to have an effective Availability Group? If I only plan to have the 2 physical servers, should I be setting up a traditional Clustered SQL Server installation.
    I've used the traditional Clustered SQL Server in the past and used the Active/Passive licensing for the SQL Server software but the Always On Availability Group looked interesting to me, but NOT if it requires more than 2 physical servers and more
    than 2 SQL Instances (and licenses) to provide proper failover capability.
    All input will be appreciated.
    Thanks,
    Brett

    Hi Brett,
    An AlwaysOn Availability Group is created between several standalone SQL Server instances, you don’t need to set up a traditional clustered SQL Server installation when configuring AlwaysOn Availability Group. Also you can have an effective Availability Group
    with only one Secondary node.
    From your description, you have an synchronous-commit availability secondary replica
    and it says Not Synchronizing. This issue can be caused by the following:
    •The availability replica might be disconnected.
    •The data movement might be suspended.
    •The database might not be accessible.
    •There might be a temporary delay issue due to network latency or the load on the primary or secondary replica.
    Please resolve any connection or data movement suspend issues. You can check the events for this issue using SQL Server Management Studio, and find the database error.
    Reference:
    Data synchronization state of some availability database is not healthy
    Availability databases in unhealthy data synchronization state (Error: 35285, Severity: 16, State: 1.)
    Thanks,
    Lydia Zhang
    If you have any feedback on our support, please click
    here.
    Lydia Zhang
    TechNet Community Support

  • How to use Pivot function for group range in oracle SQL

    Hi,
    Good Morning !!!
    I need to show the data in the below format. There is 2 columns 1 is State and another one is rate.
    State     <100     100-199     200-299     300-399     400-499     500-599     600-699     700-799     800-899     900-999     >=1000     Total
    AK     1     2     0     4     1     4     4     35     35     4     1     25
    AL     0     0     2     27     10     17     35     2     2     35     0     103
    AR     0     0     1     0     0     2     2     13     13     2     0     6
    AZ     0     1     2     14     2     14     13     3     3     13     0     57
    CA     0     0     1     6     2     7     3     4     4     3     0     34
    Developed the below query but unable to use the range on pivot function . Please help on this.
    (select      (SELECT SHORT_DESCRIPTION
         FROM CODE_VALUES
         WHERE CODE_TYPE_CODE = ad.STATE_TYPE_IND_CODE
         AND VALUE = ad.STATE_CODE
         ) STATE,
    nr.rate
         FROM neutrals n,
         contacts c,
         addresses ad,
         xref_contacts_addresses xca,
         neutral_rates nr
                        where n.contact_id=c.contact_id
                        and n.address_id = ad.address_id
                        and xca.address_id=ad.address_id
                        and xca.contact_id=c.contact_id
                        and nr.contact_id = n.contact_id
                        and nr.rate_frequency='HOUR' )

    user8564931 wrote:
    This solutions is useful and Thanks for your reply.
    How can i get the Min value and Max value for each row ?
    State     <100     100-199     200-299     300-399     400-499     500-599     600-699     700-799     800-899     900-999     >=1000     Total     Min     Max
    IL     0     0     1     5     1     5     40     1     1     40     0     53     $10     $2,500
    IN     0     0     0     0     0     0     1     49     49     1     0     3     $70     $1,500This?
    WITH t AS
            (SELECT 'AL' state, 12 VALUE FROM DUAL
             UNION ALL
             SELECT 'AL' state, 67 VALUE FROM DUAL
             UNION ALL
             SELECT 'AL' state, 23 VALUE FROM DUAL
             UNION ALL
             SELECT 'AL' state, 12 VALUE FROM DUAL
             UNION ALL
             SELECT 'AL' state, 12 VALUE FROM DUAL
             UNION ALL
             SELECT 'AL' state, 78 VALUE FROM DUAL
             UNION ALL
             SELECT 'AL' state, 34 VALUE FROM DUAL
             UNION ALL
             SELECT 'AL' state, 4 VALUE FROM DUAL
             UNION ALL
             SELECT 'AL' state, 12 VALUE FROM DUAL
             UNION ALL
             SELECT 'AL' state, 15 VALUE FROM DUAL
             UNION ALL
             SELECT 'AZ' state, 6 VALUE FROM DUAL
             UNION ALL
             SELECT 'AZ' state, 123 VALUE FROM DUAL
             UNION ALL
             SELECT 'AZ' state, 123 VALUE FROM DUAL
             UNION ALL
             SELECT 'MA' state, 23 VALUE FROM DUAL
             UNION ALL
             SELECT 'MA' state, 120 VALUE FROM DUAL
             UNION ALL
             SELECT 'MA' state, 456 VALUE FROM DUAL
             UNION ALL
             SELECT 'MA' state, 11 VALUE FROM DUAL
             UNION ALL
             SELECT 'MA' state, 24 VALUE FROM DUAL
             UNION ALL
             SELECT 'MA' state, 34 VALUE FROM DUAL
             UNION ALL
             SELECT 'MA' state, 87 VALUE FROM DUAL
             UNION ALL
             SELECT 'MA' state, 23 VALUE FROM DUAL
             UNION ALL
             SELECT 'MA' state, 234 VALUE FROM DUAL
             UNION ALL
             SELECT 'MA' state, 789 VALUE FROM DUAL
             UNION ALL
             SELECT 'MH' state, 54321 VALUE FROM DUAL),
         -- End of test data
         t1 AS
            (  SELECT state,
                      NVL (COUNT (DECODE (VALUE, 0, 0)), 0) "<100",
                      NVL (COUNT (DECODE (VALUE, 1, 1)), 0) "100-199",
                      NVL (COUNT (DECODE (VALUE, 2, 2)), 0) "200-299",
                      NVL (COUNT (DECODE (VALUE, 3, 3)), 0) "300-399",
                      NVL (COUNT (DECODE (VALUE, 4, 4)), 0) "400-499",
                      NVL (COUNT (DECODE (VALUE, 5, 5)), 0) "500-599",
                      NVL (COUNT (DECODE (VALUE, 6, 6)), 0) "600-699",
                      NVL (COUNT (DECODE (VALUE, 7, 7)), 0) "700-799",
                      NVL (COUNT (DECODE (VALUE, 8, 8)), 0) "800-899",
                      NVL (COUNT (DECODE (VALUE, 9, 9)), 0) "900-999",
                      NVL (COUNT (DECODE (VALUE, 10, 10)), 0) ">=1000"
                 FROM (SELECT state,
                              CASE
                                 WHEN VALUE < 100 THEN 0
                                 WHEN VALUE BETWEEN 100 AND 199 THEN 1
                                 WHEN VALUE BETWEEN 200 AND 299 THEN 2
                                 WHEN VALUE BETWEEN 300 AND 399 THEN 3
                                 WHEN VALUE BETWEEN 400 AND 499 THEN 4
                                 WHEN VALUE BETWEEN 500 AND 599 THEN 5
                                 WHEN VALUE BETWEEN 600 AND 699 THEN 6
                                 WHEN VALUE BETWEEN 700 AND 799 THEN 7
                                 WHEN VALUE BETWEEN 800 AND 899 THEN 8
                                 WHEN VALUE BETWEEN 900 AND 999 THEN 9
                                 WHEN VALUE >= 1000 THEN 10
                              END
                                 VALUE
                         FROM t)
             GROUP BY state)
    SELECT STATE,
           "<100",
           "100-199",
           "200-299",
           "300-399",
           "400-499",
           "500-599",
           "600-699",
           "700-799",
           "800-899",
           "900-999",
           ">=1000",
             "<100"
           + "100-199"
           + "200-299"
           + "300-399"
           + "400-499"
           + "500-599"
           + "600-699"
           + "700-799"
           + "800-899"
           + "900-999"
           + ">=1000"
              total,
         least("<100",
           "100-199",
           "200-299",
           "300-399",
           "400-499",
           "500-599",
           "600-699",
           "700-799",
           "800-899",
           "900-999",
           ">=1000") min_val,
          greatest("<100",
           "100-199",
           "200-299",
           "300-399",
           "400-499",
           "500-599",
           "600-699",
           "700-799",
           "800-899",
           "900-999",
           ">=1000") max_val
      FROM t1
    /

  • Grouping Function usage in SQL

    All,
    How does grouping function work, does it also depends on the sequence of columns used in group by rollup
      select deptno,job, group_id(), sum(sal), grouping(deptno) , grouping(job)
      from emp
      group by rollup (deptno, job) 
      If the query is run by "rollup(job,deptno)" grouping (deptno) returns 1 where as if "rollup(deptno,job)" grouping (deptno) returns 0.
    Does the column sequence in group by rollup decides the returning of grouping(deptno) function. I feel to have some misunderstanding of the way its said in ORACLE documentation. We referred to the below link for our understanding.
    http://download.oracle.com/docs/cd/E11882_01/server.112/e17118/functions071.htm
    Request the PRO's to discuss and clarify on this.

    Hi,
    ramarun wrote:
    All,
    How does grouping function work, GROUPING (x) returns 1 if the current row represents a superaggregate of x, and 0 otherwise. In other words, if GROUPING (x) is 0, then the row represents a single value of x. If GROUPING (x) is 1, then the row represents a total of all values of x.
    For example the query you posted may produce results like this:
    `   DEPTNO JOB       GROUP_ID()   SUM(SAL) GROUPING(DEPTNO) GROUPING(JOB)
            20 ANALYST            0       6000                0             0
               ANALYST            0       6000                1             0
            10 CLERK              0       1300                0             0
            20 CLERK              0       1900                0             0
            30 CLERK              0        950                0             0
               CLERK              0       4150                1             0
            10 MANAGER            0       2450                0             0
            20 MANAGER            0       2975                0             0
            30 MANAGER            0       2850                0             0
               MANAGER            0       8275                1             0
            10 PRESIDENT          0       5000                0             0
               PRESIDENT          0       5000                1             0
            30 SALESMAN           0       5600                0             0
               SALESMAN           0       5600                1             0
                                  0      29025                1             1Look at the last three rows. On this row
    `   DEPTNO JOB       GROUP_ID()   SUM(SAL) GROUPING(DEPTNO) GROUPING(JOB)
            30 SALESMAN           0       5600                0             0GROUPING (deptno) is 0; so the row represents only deptno=30.
    GROUPINT (job) is 0, so the row represents only job='SALESMAN'.
    SUM (sal) is 5600, so the total salary of all salesmen in department 30 is 5600.
    Now look at this row:
    `   DEPTNO JOB       GROUP_ID()   SUM(SAL) GROUPING(DEPTNO) GROUPING(JOB)
               SALESMAN           0       5600                1             0GROUPING (deptno) is 1; so the row does not represent any one deptno; it is a superaggregate of all deptnos. Notice that the deptno column is NULL, even though there are no rows in the table where deptno is NULL.
    GROUPING (job) is 0, so the row represents only job='SALESMAN'.
    SUM (sal) is 5600, so the total salary of all salesmen in any department is 5600. (As it happens, all the salesmen are in department 30, so this sum is the same as on the previous row.)
    Now look at the last row:
    `   DEPTNO JOB       GROUP_ID()   SUM(SAL) GROUPING(DEPTNO) GROUPING(JOB)
                                  0      29025                1             1GROUPING (deptno) is 1; so the row does not represent any one deptno; it is a superaggregate of all deptnos. Notic that both deptno and job are both NULL on this row of output, even though neither column is ever NULL in the table.
    GROUPING (job) is 0, so the row represents only job='SALESMAN'.
    SUM (sal) is 5600, so the total salary of people with any job and any department is 29025.
    does it also depends on the sequence of columns used in group by rollup Excellent question! Try it an see. Change the order or columns in the GROUP BY clause and see. If you get different results, then the order does matter.
    select deptno,job, group_id(), sum(sal), grouping(deptno) , grouping(job)
    from emp
    group by rollup (deptno, job)  If the query is run by "rollup(job,deptno)" grouping (deptno) returns 1 where as if "rollup(deptno,job)" grouping (deptno) returns 0. You get different results; therefore the order does matter.
    Does the column sequence in group by rollup decides the returning of grouping(deptno) function...Yes.
    "GROUP BY ROLLUP (deptno, job)" means a superaggregate row for each value of job, representing all deptnos, will be formed. That is, you will get one row representing all analysts; another row representing all clerks, another row representing all managers, and so on. This will be similar to the results that you would get if you never mentioned the first expression in the ROLLUP list, that is, deptno. You will not get a superaggregate row representing any one deptno, say, 10.
    "GROUP BY ROLLUP (job, deptno)" means a superaggregate row for each value of deptno, representing all jobs, will be formed. That is, you will get one row representing all anlysts; another row representing deprtment 10, another row representing department 20, and so on. This will be similar to the results that you would get if you never mentioned the first expression in the ROLLUP list, that is, job. You will not get a superaggregate row representing any one job, say, 'ANALYST'.

Maybe you are looking for

  • .docx no longer opening on my iPad air, when I could open them before?

    i Have had .docx file types sent to me as recent as September 2014, which I could open simply by tapping on the attachment. Now October 2014, they will not open? Why? can this by changed back to all me to open the .docx which I have attached to mail

  • 3.1.4.710 DataModeler - Not able to see captured sequences

    I have imported a schema successfully and can see the sequences that I captured when I try to synchronize with the database (they are listed as items). However if I wanted to create a NEW sequence or modify the starting number I am unable to expand t

  • Customer Interface problem

    Dear All, I am working on customer interface.. everything is working fine . i am inserting customer's header leval contact information everything is working okay only problem that i am having is i am not able to insert website addresses on header ..

  • Setting headers to the HttpRequest

    How to set content in header of the ServletRequest.. Can any body please help me ..

  • Chromebook bluetooth

    Hello, I have a chromebook 14, and I am trying to use a MS Bluetooth mouse (Microsoft Intellimouse Explorer for Bluetooth). I can see the mouse when I open the bluetooth settings, but when I try to connect the mouse, it says 'connection failed'. The