Simplify the query/select statement help

select distinct B_Billing_key, B_COMPANY_ID "Company" ,
to_char(to_date('01/'||trim(substr(B_REPORT_PERIOD,5,2))||'/'||
trim(substr(B_REPORT_PERIOD,1,4)),'DD/MM/YYYY'),'Month YYYY') "Billing Period",
(nvl(SURCH_AMOUNT,0)+nvl(ADJUST_AMOUNT,0)+nvl(PI_AMOUNT,0))-(nvl(sum(AMOUNT),0))"Period_Balance",
decode(sign((nvl(SURCH_AMOUNT,0)+nvl(ADJUST_AMOUNT,0)+nvl(PI_AMOUNT,0))-(nvl(sum(AMOUNT),0))),1, 'Yes'
,'No'
)"outstanding_balance"
p.PROGRAM_NAME_ID|| ' . ' ||p.PROGRAM_NAME_DESCR "Programname"
FROM tuff_balance_view,MV_PROG_SURCH S,MV_PAYMENT_HOLDING H,MV_PROGRAM_DICT P where
b_company_id = 'XYZ'
and B_Billing_key=s.BILLING_KEY
and S.PROGRAM_KEY = P.PROGRAM_KEY
and P.PROGRAM_KEY= H.PROGRAM_KEY
GROUP BY B_Billing_key,B_COMPANY_ID,B_REPORT_PERIOD,SURCH_AMOUNT,ADJUST_AMOUNT,PI_AMOUNT,PROG_SURCH_KEY,
S.PROGRAM_KEY,p.PROGRAM_NAME_ID|| ' . ' ||p.PROGRAM_NAME_DESCR,AMOUNT
order by B_Billing_key desc
B_Billing_key is the primary key. I am looking for the output only one record for each biling perid. there are 2 programs for each billing period. if any of the program has period balance >0 then outstanding balance should be yes.
The output from the above query is as below.
biling_key company billing period period_balance outstandingbalance programname
123 xyz January 2011 4 Yes ABC
123 xyz January 2011 -5 NO DEF
456 xyz February 2011 -3.0 No ABC
456 xyz February 2011 2 Yes DEF
Need the output as below from the above query. Can you please help to simplify query. If anyof theprogram having outstanding balance for that particular period show the outstandigbalance as yes. Else NO.
     company billing period outstandingbalance programname
xyz January 2011 Yes ABC
xyz February 2011 Yes DEF
Thanks,
vi

<font face="courier">
<font color="green">-- this just simulates the results of your original query - meant just to play with until everything works</font>
<br>
with
your_query as
(select 123 billing_key,'xyz' company,'Jan 2011' billing_period,'No' outstandingbalance,'ABC' programname from dual union all
 select 123,'xyz','Jan 2011','Yes','DEF' programname from dual union all
 select 123,'xyz','Jan 2011','No','GHI' programname from dual union all
<font color="green">--comment out some data row to see what happens when having just 5 programs
--</font> select 123,'xyz','Jan 2011','No','JKL' programname from dual union all
 select 123,'xyz','Jan 2011','Yes','MNO' programname from dual union all
 select 123,'xyz','Jan 2011','No','PQR' programname from dual union all
 select 456,'xyz','Feb 2011','No','ABC' programname from dual union all
 select 456,'xyz','Feb 2011','No','DEF' programname from dual union all
 select 456,'xyz','Feb 2011','No','GHI' programname from dual union all
 select 456,'xyz','Feb 2011','No','JKL' programname from dual union all
 select 456,'xyz','Feb 2011','No','MNO' programname from dual union all
 select 456,'xyz','Feb 2011','No','PQR' programname from dual
<font color="green">-- end of generated data
-- the "real" query follows
</font>
<br>
<font color="blue">
select billing_key,
       company,
       billing_period,
       case when programname = ',,,,,' then 'No' else 'Yes' end outstandingbalance,
       case when programname != ',,,,,'
            then trim(',' from replace(replace(replace(programname,',',',~'),'~,'),'~'))
       end programname
  from (select billing_key,company,billing_period,'Yes' outstandingbalance,
               max(case when outstandingbalance = 'Yes' and programname = 'ABC' then 'ABC' end) || ',' ||
               max(case when outstandingbalance = 'Yes' and programname = 'DEF' then 'DEF' end) || ',' ||
               max(case when outstandingbalance = 'Yes' and programname = 'GHI' then 'GHI' end) || ',' ||
               max(case when outstandingbalance = 'Yes' and programname = 'JKL' then 'JKL' end) || ',' ||
               max(case when outstandingbalance = 'Yes' and programname = 'MNO' then 'MNO' end) || ',' ||
               max(case when outstandingbalance = 'Yes' and programname = 'PQR' then 'PQR' end) programname
          from (
                 <font color="green">--your_query here</font><br>
<font color="red">
                select distinct B_Billing_key, B_COMPANY_ID "Company" ,
                to_char(to_date('01/'||trim(substr(B_REPORT_PERIOD,5,2))||'/'||
                trim(substr(B_REPORT_PERIOD,1,4)),'DD/MM/YYYY'),'Month YYYY') "Billing Period",
                (nvl(SURCH_AMOUNT,0)+nvl(ADJUST_AMOUNT,0)+nvl(PI_AMOUNT,0))-(nvl(sum(AMOUNT),0))"Period_Balance",
                decode(sign((nvl(SURCH_AMOUNT,0)+nvl(ADJUST_AMOUNT,0)+nvl(PI_AMOUNT,0))-(nvl(sum(AMOUNT),0))),1, 'Yes'
                ,'No'
                )"outstanding_balance"
                p.PROGRAM_NAME_ID|| ' . ' ||p.PROGRAM_NAME_DESCR "Programname"
                FROM tuff_balance_view,MV_PROG_SURCH S,MV_PAYMENT_HOLDING H,MV_PROGRAM_DICT P where
                b_company_id = 'XYZ'
                and B_Billing_key=s.BILLING_KEY
                and S.PROGRAM_KEY = P.PROGRAM_KEY
                and P.PROGRAM_KEY= H.PROGRAM_KEY
                GROUP BY B_Billing_key,B_COMPANY_ID,B_REPORT_PERIOD,SURCH_AMOUNT,ADJUST_AMOUNT,PI_AMOUNT,PROG_SURCH_KEY,
                S.PROGRAM_KEY,p.PROGRAM_NAME_ID|| ' . ' ||p.PROGRAM_NAME_DESCR,AMOUNT
                order by B_Billing_key desc
</font>
         group by billing_key,company,billing_period
</font>
</font>
Regards
Etbin
your simplified query should look somehow like below
you didn't provide table structures and sample data so:
aliases were assigned arbitrarily
using sum(nvl(s.SURCH_AMOUNT,0) + nvl(s.ADJUST_AMOUNT,0) + nvl(s.PI_AMOUNT,0) - nvl(v.AMOUNT,0)) is most certainly wrong
select v.B_Billing_key,
       v.B_COMPANY_ID company,
       to_char(to_date(substr(v.B_REPORT_PERIOD,1,6),'yyyymm'),'Month yyyy') billing_period
       case when sum(nvl(s.SURCH_AMOUNT,0) + nvl(s.ADJUST_AMOUNT,0) + nvl(s.PI_AMOUNT,0) - nvl(v.AMOUNT,0)) > 0
            then 'Yes'
            else 'No'
       end outstandingbalance,
       p.PROGRAM_NAME_ID programname
  FROM tuff_balance_view v,
       MV_PROG_SURCH S,
       MV_PAYMENT_HOLDING H,
       MV_PROGRAM_DICT P
where v.B_COMPANY_ID = 'U-7052-C'
   and v.B_Billing_key = s.BILLING_KEY
   and S.PROGRAM_KEY = P.PROGRAM_KEY
   and P.PROGRAM_KEY = H.PROGRAM_KEY
group by B_Billing_key,
          B_COMPANY_ID,
          to_char(to_date(substr(B_REPORT_PERIOD,1,6),'yyyymm'),'Month yyyy'),
          p.PROGRAM_NAME_IDEdited by: Etbin on 2.3.2011 22:44

Similar Messages

  • Increase performance of the following SELECT statement.

    Hi All,
    I have the following select statement which I would want to fine tune.
      CHECK NOT LT_MARC IS INITIAL.
      SELECT RSNUM
             RSPOS
             RSART
             MATNR
             WERKS
             BDTER
             BDMNG FROM RESB
                          INTO TABLE GT_RESB 
                          FOR ALL ENTRIES IN LT_MARC
                          WHERE XLOEK EQ ' '
                          AND MATNR EQ LT_MARC-MATNR
                          AND WERKS EQ P_WERKS
                          AND BDTER IN S_PERIOD.
    The following query is being run for a period of 1 year where the number of records returned will be approx 3 million. When the program is run in background the execution time is around 76 hours. When I run the same program dividing the selection period into smaller parts I am able to execute the same in about an hour.
    After a previous posting I had changed the select statement to
      CHECK NOT LT_MARC IS INITIAL.
      SELECT RSNUM
             RSPOS
             RSART
             MATNR
             WERKS
             BDTER
             BDMNG FROM RESB
                          APPENDING TABLE GT_RESB  PACKAGE SIZE LV_SIZE
                          FOR ALL ENTRIES IN LT_MARC
                          WHERE XLOEK EQ ' '
                          AND MATNR EQ LT_MARC-MATNR
                          AND WERKS EQ P_WERKS
                          AND BDTER IN S_PERIOD.
      ENDSELECT.
    But the performance improvement is very negligible.
    Please suggest.
    Regards,
    Karthik

    Hi Karthik,
    <b>Do not use the appending statement</b>
    Also you said if you reduce period then you get it quickly.
    Why not try dividing your internal table LT_MARC into small internal tables having max 1000 entries.
    You can read from index 1 - 1000 for first table. Use that in the select query and append the results
    Then you can refresh that table and read table LT_MARC from 1001-2000 into the same table and then again execute the same query.
    I know this sounds strange but you can bargain for better performance by increasing data base hits in this case.
    Try this and let me know.
    Regards
    Nishant
    > I have the following select statement which I would
    > want to fine tune.
    >
    >   CHECK NOT LT_MARC IS INITIAL.
    > SELECT RSNUM
    >          RSPOS
    > RSART
    >          MATNR
    > WERKS
    >          BDTER
    > BDMNG FROM RESB
    >                       INTO TABLE GT_RESB 
    > FOR ALL ENTRIES IN LT_MARC
    >                       WHERE XLOEK EQ ' '
    > AND MATNR EQ LT_MARC-MATNR
    >                       AND WERKS EQ P_WERKS
    > AND BDTER IN S_PERIOD.
    >  
    > e following query is being run for a period of 1 year
    > where the number of records returned will be approx 3
    > million. When the program is run in background the
    > execution time is around 76 hours. When I run the
    > same program dividing the selection period into
    > smaller parts I am able to execute the same in about
    > an hour.
    >
    > After a previous posting I had changed the select
    > statement to
    >
    >   CHECK NOT LT_MARC IS INITIAL.
    > SELECT RSNUM
    >          RSPOS
    > RSART
    >          MATNR
    > WERKS
    >          BDTER
    > BDMNG FROM RESB
    > APPENDING TABLE GT_RESB
    >   PACKAGE SIZE LV_SIZE
    >                     FOR ALL ENTRIES IN LT_MARC
    >   WHERE XLOEK EQ ' '
    >                     AND MATNR EQ LT_MARC-MATNR
    >   AND WERKS EQ P_WERKS
    >                     AND BDTER IN S_PERIOD.
    > the performance improvement is very negligible.
    > Please suggest.
    >
    > Regards,
    > Karthik
    Hi Karthik,

  • The query processor ran out of stack space during query optimization. Please simplify the query

    Can you suggest me that what should i do in this case.
    Actually i am having one table that is a MasterTable.I am referring this table in more than 300 tables that means i am having foreign key of this primary key in 300+ tables.
    due to this i am getting following error during deleting any row,
    doesn't matter that data is existing in reference table or not.
    Error that i am getting is 
    "The query processor ran out of stack space during query optimization. Please simplify the query"
    Can you suggest me that what should i do to avoid this error,because i am unable to delete this entry.
    Apart from it,i am getting performance problem too,so is it due to such huge FK on it.
    Please suggest me on following points
    1. Is it worst way to handle it,if yes then please suggest me solution for it.
    2. If it is a correct way then what should i do if getting error during deleting any record.
    3. Is it right to create Foreign key on each table where i am saving data of this master. if no then how to manage integrity.
    4. What people do in huge database when they wants to create foreign key for any primary key.
    5. Can you suggest me that how DBA's are handling this in big database,where they are having huge no. of tables.

    The most common reason of getting such error is having more than 253 foreign key constraints on a table. 
    The max limit is documented here:
    http://msdn.microsoft.com/en-us/library/ms143432(SQL.90).aspx 
    Although a table can contain an unlimited number of FOREIGN KEY constraints, the recommended maximum is 253. Depending on the hardware configuration hosting SQL Server, specifying additional foreign key constraints may be expensive for the query
    optimizer to process. If you are on 32 bit, then you might want to move to 64 bit to get little bigger stack space but eventually having 300 FK is not something which would work in long run.
    Balmukund Lakhani | Please mark solved if I've answered your question, vote for it as helpful to help other users find a solution quicker
    This posting is provided "AS IS" with no warranties, and confers no rights.
    My Blog |
    Team Blog | @Twitter
    Author: SQL Server 2012 AlwaysOn -
    Paperback, Kindle

  • Splitting the huge SELECT statement

    Hi Gurus,
    I need help in order to split the huge SELECT statement into individual select for each table (AFKO, AFVC)...I don't have to much experience into that, could someone guide me into or provide finished code?
    Thanks
    OPEN CURSOR WITH HOLD s_cursor FOR
    SELECT
    t1~mandt AS mandt
    t1~aufnr AS aufnr
    t1~aufpl AS aufpl
    t2~aplzl AS aplzl
    t2~banfn AS banfn
    t2~bnfpo AS bnfpo
    t3~ebeln AS ebeln
    t3~ebelp AS ebelp
    t4~vgabe AS vgabe
    t4~belnr AS belnr
    t4~buzei AS buzei
    t4~gjahr AS gjahr
    t4~zekkn AS zekkn
    t4~srvpos AS srvpos
    t6~menge AS menge "D02K924592
    t3~dmbtr AS dmbtr "D02K924378
    t4~cpudt AS cpudt
    t4~shkzg AS shkzg
    t4~budat AS budat
    t3~lifnr AS lifnr
    t2~vornr AS vornr_sactv
    t7~vornr AS vornr_actv
    t2~sumnr AS sumnr
    t2~prctr AS prctr
    t6~meins AS meins "D02K924592
    t3~waers AS waers "D02K924378
    t3~sakto AS kstar "D02K924456
    t6~packno AS packno "D02K924592
    t6~introw AS introw "D02K924592
    FROM afko AS t1
    INNER JOIN afvc AS t2 ON t2mandt = t1mandt
    AND t2aufpl = t1aufpl
    INNER JOIN mseg AS t3 ON t3mandt = t2mandt "D02K924373
    AND t3aufpl = t2aufpl "D02K924373
    AND t3aplzl = t2aplzl "D02K924373
    INNER JOIN ekbe AS t4 ON t4mandt = t3mandt
    AND t4ebeln = t3ebeln
    AND t4ebelp = t3ebelp
    AND t4zekkn = t3zekkn "D02K924373
    AND t4~vgabe = 1 "D02K924373
    AND t4gjahr = t3mjahr "D02K924373
    AND t4belnr = t3mblnr "D02K924373
    AND t4buzei = t3zeile "D02K924373
    INNER JOIN t430 AS t5 ON t5mandt = t2mandt "D02K924489
    AND t5~plnaw = '*' "D02K924489
    AND t5steus = t2steus "D02K924489
    AND t5~service = 'X' "D02K924489
    LEFT OUTER JOIN esll AS t6 ON t6mandt = t4mandt "D02K924592
    AND t6packno = t4packno "D02K924592
    AND t6introw = t4introw "D02K924592
    INNER JOIN afvc AS t7 ON t2mandt = t7mandt
    AND t2aufpl = t7aufpl
    AND t2sumnr = t7aplzl
    WHERE t1~mandt = sy-mandt
    AND t1~aufnr LIKE '00006%'
    AND t1~aufnr IN l_r_aufnr
    AND t2~prctr = '0000005080'
    AND t2~sumnr '00000000'
    AND t4~vgabe = 1
    AND t4~cpudt IN l_r_cpudt
    AND t2~steus IN l_r_steus "D02K924627
    AND t5~steus IN l_r_steus. "D02K924627.
    Regards

    you can use for all entries option like this...
    " first select data from first table
    data: it_table1 type table of afko .
    SELECT
    t1~mandt
    t1~aufnr
    t1~aufpl
    FROM afko  as t1
    WHERE t1~mandt = sy-mandt
    AND t1~aufnr LIKE '00006%'
    AND t1~aufnr IN l_r_aufnr into table it_table1 .
    " then we ll select the data from second table using the entries selected from the first table and field conditions for second tabel itself.
    data: it_table2 type table of afvc .
    select
    t2~aplzl
    t2~banfn
    t2~bnfpo
    t2~vornr
    t2~sumnr
    t2~prctr
    from afvc as t2 into table it_table2
    for all entries in it_table1
    where it_table1-mandt = t2~mandt
    and   it_table1-aufpl = t2~aufpl
    and t2~prctr = '0000005080'
    AND t2~sumnr '00000000'
    AND t2~steus IN l_r_steus "D02K924627 .
    " then we ll select the data from third table using the entries selected from the first and second table and field conditions for second tabel itself.
    data: it_table3 type table of mseg .
    select
    t3~ebeln AS ebeln
    t3~ebelp AS ebelp
    t3~dmbtr AS dmbtr "D02K924378
    t3~lifnr AS lifnr
    t3~waers AS waers "D02K924378
    t3~sakto AS kstar "D02K924456
    from mseg AS t3
    for all entries in it_table2
    where it_table2-mandt = t3~mandt
    and it_table2-aufpl = t3~aufpl
    and it_table2-aplzl = t3~aplzl .
    like wise u can do for all the tables you have...
    Edited by: prashanti korlepara on Jun 16, 2011 3:41 PM

  • Change the default select statement in the execute_query function

    I want to list all records where c1 like '%ABD%'. So I set the following in the 'when_button_pressed' tigger:
    set_block_property ('block_name',DEFAULT_WHERE,'upper(c1) like '''||'%'||:block_name.blk_col_name||'%'||'''');
    execute_query;
    When I click on the button the :system.last_query holds the following select statement:
    select c1, c2, .. cn from t_n where upper(c1) like '%ABD%' and (upper(c1) = 'ABD' and (c1 like 'ab%' or c1 like 'aB%' or c1 like 'Ab%' or c1 like 'AB%')) order by c1
    Since the condition upper(c1) = 'ABD' is not satisfied oracle does not return any rows.
    My question is how to overcome this or is it possible to change the built-in select statement of execute_query.

    Have you tried this :
    'upper(c1) like upper('''||'%'||:block_name.blk_col_name||'%'||''''));

  • Delete adjacent duplicates how to use in the below select statement

    hi i have a problem
    i am suing the below select statement
    SELECT    a~extno
              a~guid_lclic       " for next select
              e~ctsim
              e~ctsex
    *revised spec 3rd
              f~guid_pobj
              f~amnt_flt
              f~amcur
              f~guid_mobj
              e~srvll     "pk
              e~ctsty     "PK
              e~lgreg  "PK
      INTO TABLE gt_sagmeld
      FROM /SAPSLL/LCLIC  as a
      INNER JOIN /sapsll/tlegsv as e on elgreg = algreg
      inner join /sapsll/legcon as f on fguid_lclic = aguid_lclic   " for ccngn1 selection
      inner join /sapsll/corcts as g on gguid_pobj = fguid_pobj
                               where   a~extno in s_extno.
      sort gt_sagmeld by guid_lclic lgreg ctsty srvll GUID_POBJ GUID_MOBJ.
      delete adjacent duplicates from gt_sagmeld comparing guid_lclic lgreg ctsty srvll GUID_POBJ GUID_MOBJ .
    now i am confused how to use delete adjacent dupliacate and on which fields
    as first table /sal../lclic primary key is guid_lclic
    and it is joined to table
    legcon by guid_lclci ( not a primary key here)
    legcon primary key is guid_legcon
    and table 3 legsv by lgreg (pk here)
    table 3 has tow more primary key srvll and ctsty also
    NOW MY QUESTIO IS TAHT IS I USE ABOVE DELETE ADJACENT STATMENT IT FETCHES 20 LAKH RECORDS
    I WANT TO REDUCE IS LET ME KNOW ON WHAT fields i need to use delete adjacen duplicates
    or use comparing all fields?
    regards
    Arora

    hi sudha
    if u see my select statement is contains four Primary keys
    srvll
    lgreg
    ctsty
    guid_lclic
    but the next table connected to this table legcon is by guid_pobj and anothe table by guid_mobj
    and if i take this gt_sagmeld to another temp table and i find abt 10 lakh uniques guid_pobj
    similary 6 lakh guid_mobj so the next slect is hanpering because of this
    not COMING TO OUR POINT IF I SORT ONLY BY OUR PRIMARY KEYS NOT TAKING INTO ACCOUNT TEH GUID_POBJ AND GUID_MOBJ
    THE ENTRIES ARE VERY LESS BUT IF I TAKE INOT ACCCOUNT IN GT_SAGMELD THE ENTRIES ARE ABT 20 LAKH
    SO I AM NOT SURE WHETHER TO TAKNE GUID_POBJ AND GUID_MOBJ INOT ACCOUNT FOR DELECTING ADJACENT DUPLICATES?
    HENCE THE QUESTION OF ON WHICH FIRLD DELETE OR COMPARING ALL FIELDS I USE?

  • DiscoverSQL2005DBEngineDiscovery.vbs : The Query 'select * from __NAMESPACE where Name ='ComputerManagement'' returned an invalid result set.

    hi
    I am keep receiving this message in central administration running server in event viewer
    DiscoverSQL2005DBEngineDiscovery.vbs : The Query 'select * from __NAMESPACE where Name ='ComputerManagement'' returned an invalid result set.  Please check to see if this is a valid WMI Query.. Object required
    adil

    Hi adil,
    It seems to be not related to SharePoint issue, I find a similar error post from Operations Manager forum you can take a look
    Also another below article of basic troubleshooting of discovery scripts for your reference.
    And for the further better assistance regarding this issue, you may want to post Operations Manager forum here.
    http://social.technet.microsoft.com/Forums/systemcenter/en-US/21e9de85-5cbc-4217-8d9b-921e13dc88dc/sql-mp-issues-with-discovery-vbs-scripts?forum=operationsmanagermgmtpacks
    http://blogs.technet.com/b/kevinholman/archive/2010/03/09/basic-troubleshooting-of-discovery-scripts.aspx
    Thanks
    Daniel Yang
    TechNet Community Support

  • Help with a query using ISNULL and RTRIM in the same select statement

    What I'm trying to accomplish is to blend the following two statements together:
    ISNULL (EMail_Address, '') As Matrix_Member_Email
     AND
    RTRIM (EMail_Address) as Matrix_Member_EMail
    So that if the email address is NULL, it gets changed to blank and I still need to RTRIM the other entries and use the column header of Matrix_Member_Email.
    I've tried:
    ISNULL ((EMail_Address, '') (RTRIM (EMail_Address)) as Matrix_Member_EMail
    Any help would be greatly appreciated.
    Thank you,

    I'm sorry.  Here is the query:
    --Declare @EMail_Address nvarchar(100) = null
    Select SVAssociationID.R_ShortValue as MATRIX_AssociationID, Matrix_Modified_DT as Matrix_LastModified
      ,RTRIM (MLS_ID) As Matrix_MLS_ID
      , ISNULL(EMail_Address, '') AS MATRIX_member_Email
      ,RTRIM (EMail_Address) as Matrix_Member_EMail
      --,RTRIM( LTRIM(  ISNULL (@EMail_Address, '') ) ) as Matrix_Member_EMail 
      ,Last_Name AS MATRIX_LastName, Nickname AS MATRIX_NickName
      FROM    dbo.Agent_Roster_VIEW a
            LEFT JOIN dbo.select_values_VIEW SV ON a.Status_SEARCH = SV.ID
            LEFT JOIN dbo.select_values_VIEW BillType ON a.Bill_Type_Code_SEARCH = BillType.ID
      LEFT JOIN dbo.select_values_VIEW SVAssociationID ON A.Primary_Association_SEARCH = SVAssociationID.ID
    WHERE   Status_SEARCH IN (66,68) 
        Order by MLS_ID
    Results:
    MATRIX_AssociationID
    Matrix_LastModified
    Matrix_MLS_ID
    MATRIX_member_Email
    Matrix_Member_EMail
    MATRIX_LastName
    MATRIX_NickName
    STC
    09/02/14
    CCWILLI
    [email protected]
    [email protected]
    Williams                      
    Christine   
    STC
    09/12/14
    CCWORSL
    [email protected]
    [email protected]
    Worsley                       
    Charlie
    STC
    09/02/14
    CCYROBIN
    NULL
    Robinson       
    ECBR
    09/02/14
    CDABLACK
    [email protected]
    [email protected]
    Black                         
    Dale        
    STC
    09/02/14
    CDABRADY
    [email protected]
    [email protected]
    Brady                         
    David       
    Thank you,

  • XSQL bug  when using CURSOR in xsql:query SELECT statement?

    Hi there,
    When I tested with different XSQL pages, I found out that if I
    did not involve any XSQL pages that contain "CURSOR", I received
    data correctly and when I shut down Tomcat, Oracle DB server did
    NOT create any dump file (???). However, as long as I involve a
    XSQL page which contains "CURSOR", even I received data
    correctly, but when I shut down my Tomcat, Oracle DB server
    created a dump file (???).
    for example, if I involve xsql:query like:
    <xsql:query>
    SELECT emp_name,
    emp_id
    CURSOR( SELECT emp_address
    from address a
    where a.emp_id = b.emp_id)
    FROM employee b
    </xsql:query>
    Once, I involve this xsql page, when I shut down Tomcat, Oracle
    dB will create a dump file on the server.
    Even when I run this xsql page from
    oracle.xml.xsqlXSQLCommandLine, Oracle dB server still create a
    dump file on the server.
    Any idea for help ?
    Thanks,

    Hi,
    Is this what you are trying:
        try {
        Statement *stmt = conn->createStatement("SELECT ename AS aaaaaaaaaaaaaaa  FROM emp");
          ResultSet *rs = stmt->executeQuery ();
          vector<MetaData> md = rs->getColumnListMetaData ();
          int numCols = md.size ();
          cout<< "Number of columns :" << numCols << endl;
          string *colName = new string [numCols];
          int type = (int ) malloc (numCols);
          for (int i = 0; i < numCols; i++ ) {
            int ptype = md [ i ].getInt (MetaData::ATTR_PTYPE);
            if ( ptype == MetaData::PTYPE_COL ) {
              colName[ i ] = md[ i ].getString (MetaData::ATTR_NAME);
              cout<<"Column Name :" << colName[ i ] << endl;
          delete[] colName;
          stmt->closeResultSet (rs);
          conn->terminateStatement (stmt);
        catch (SQLException &ex) {
                    cout<<ex.getMessage()<<endl;
        }The above snippet works correctly for me.
    Rgds.
    Amogh

  • MySQL Select Statement Help Required

    I am trying to generate a report in VS 2008 (C#) using a mysql select statement but cannot get it right.
    I have groups that meet on a weekly basis on different days. I want to generate a report that shows me all the members that have not attended their group where they have missed 3 meetings in a row.
    Below is the select statement I have tried but it does not give me the results I am looking for. I have tried to look at all the meetings in a 4 week period but would prefer to look at the last 3 meetings that are recorded. Some groups might not record a meeting every week. So I want to look at the last 3 recorded meetings and count each members attendance and only report on the members with more than 3 meetings missed.
    SELECT COUNT(`groupattendance`.`Attended`) AS Attendance, `smallgroupform`.`MeetingDate`, `userinfo`.`FirstName`, `userinfo`.`Surname`, `smallgroup`.`GroupName`, `groupattendance`.`Attended`, `groupattendance`.`UserID`, `groupattendance`.`GroupID`
    FROM ((`anatomy`.`groupattendance` `groupattendance`
    INNER JOIN `anatomy`.`smallgroupform` `smallgroupform` ON `groupattendance`.`FormID` = `smallgroupform`.`FormID`)
    INNER JOIN `anatomy`.`userinfo` `userinfo` ON `groupattendance`.`UserID` = `userinfo`.`UserID`)
    INNER JOIN `anatomy`.`smallgroup` `smallgroup` ON `groupattendance`.`GroupID` = `smallgroup`.`GroupID`
    WHERE (`smallgroupform`.`MeetingDate` >= DATE_SUB(CURDATE(),INTERVAL 4 WEEK) AND `smallgroupform`.`MeetingDate` <= CURDATE()) AND `groupattendance`.`Attended` = 'False'
    GROUP BY `userinfo`.`UserID`
    HAVING Attendance >= 3
    Thanks,
    Garth.

    Hi Garth,
    Seems no one can help you directly. Try googling your SQL request. Someone may be able to help you. At this point its not really a Cr problem.
    One option is to get all the data and add filtering using the record selection formula.
    Thank you
    Don

  • How to set "like" field of the query in statements

    Hi,
    Im trying to set the "like" field of the statement.but it is not executing as expected.Could anybody please tell me,"how to set the like field in statements.
    Here is my code.
    PreparedStatement psum=con.prepareStatement("select count(bill_amount) from master where bill_date like ? and whos_bu=?");
    String myStr=month+"/??/"+year;
    psum.setString(1,myStr);
    psum.setString(2,employeeTray[1]);
    ResultSet rs=psum.executeQuery();

    Tnx a lot vidyut .using % is working.
    Could you plz tell me why the previous one using question mark is not
    working. using quesion mark is correct as per the query syntax.and also i tried with asterisk,it is also not working.
    ps:have some duke dollars.

  • Alias of a table is not recognized in the nested select statement

    Hi,
    I have to migrate a query in DB2 to Oracle. The query in DB2 uses Fetch First Row, this is being replaced by Rownum as follow.
    DB2 Query
    SELECT S.ID AS ID, (SELECT VALUE_N FROM ARCHIVE.PACKAGE_PARAMETERS WHERE PACKAGE_ID = S.ID AND ROWNUM < 2) AS HUB_UNIT_ID FROM ARCHIVE.SHIPMENTS S WHERE S.ARCHIVE_ID < 900
    This is working fine
    Oracle Query
    SELECT S.ID AS ID, ( SELECT VALUE_N FROM (SELECT VALUE_N FROM ARCHIVE.PACKAGE_PARAMETERS WHERE PACKAGE_ID = S.ID ) tempTable where ROWNUM < 2) AS HUB_UNIT_ID FROM ARCHIVE.SHIPMENTS S WHERE S.ARCHIVE_ID < 900
    This is throwing error
    Error: ORA-00904: "S"."ID": invalid identifier
    Table Script
    CREATE TABLE "ARCHIVE"."PACKAGE_PARAMETERS" (
    "ID" NUMBER(19,0) NOT NULL ,
    "PACKAGE_ID" NUMBER(19,0) ,
    "DESCRIPTION" VARCHAR(128) ,
    "VALUE_N" VARCHAR(128) ,
    "NOTES" VARCHAR(512) )
    CREATE TABLE "ARCHIVE"."SHIPMENTS" (
    "ID" NUMBER(19,0) NOT NULL ,
    "CREATED" DATE DEFAULT SYSDATE NOT NULL ,
    "CI_INSURANCE_CHARGE" FLOAT DEFAULT 0 NOT NULL ,
    "ARCHIVE_ID" NUMBER(19,0) ,
    Please suggest me some alternative.
    Let me know if you need more information.
    Regards,
    Anil Sinha

    SELECT S.ID AS ID, ( SELECT VALUE_N FROM (SELECT VALUE_N FROM >>ARCHIVE.PACKAGE_PARAMETERS WHERE PACKAGE_ID = S.ID ) >>tempTable where ROWNUM < 2) AS HUB_UNIT_ID FROM >>ARCHIVE.SHIPMENTS S WHERE S.ARCHIVE_ID < 900
    This is throwing error
    Error: ORA-00904: "S"."ID": invalid identifierBecause S.ID is out of scope of correlated subquery. See:
    http://download-uk.oracle.com/docs/cd/B10501_01/server.920/a96540/queries8.htm#2054088
    Has to be formally:
    SELECT S.ID AS ID,
    (SELECT VALUE_N FROM ARCHIVE.PACKAGE_PARAMETERS WHERE PACKAGE_ID = S.ID AND ROWNUM < 2) AS HUB_UNIT_ID
    FROM ARCHIVE.SHIPMENTS S WHERE S.ARCHIVE_ID < 900
    But to be honest it's doubtful logic to use arbitrary row from multi-row subquery as the source for column value...
    Rgds.

  • Please help me in completing the remaining select statements

    1.     Based on the selection made from the selection screen, get PO Number (EBELN), Company Code (BUKRS), Vendor (LIFNR), Vendor Name (ZNAME1), PO_Date (AEDAT), PO Creator (ERNAM) from EKKO table
    2.     For the corresponding PO number (EBELN) from EKKO table, get  PO Item Text (TXZ01) from EKPO table
    3.     For the corresponding PO number (EBELN) from EKKO table, get PO_Iten_No(EBELP), from EKPO table
    4.     For the corresponding PO number (EBELN) from EKKO table get the GR_Posting Dt(BUDAT) from EKBE table when PO History cat (HCT-EKBE) is equal to “E” .
    a)     For getting the first GR Posting date and first Invoice posting date, sort the column (BUDAT) of table, get the 1st GR_Posting_dt(BUDAT) when PO History cat (HCT-EKBE) is equal to “E”  AND get the 1st Inv_Posting_Dt(BUDAT) when PO when PO History cat (HCT-EKBE) is equal to “Q” For this corresponding invoice date (when when PO History cat (HCT-EKBE) is equal to “Q” ) get the invoice number (BELNR) .
    b)     IF  1ST GR_POSTING_DATE < 1ST INVOICE_POSTING_DATE, DO NOT DISPLAY THE RESULT
    5.     For the corresponding PO number (EBELN) from EKKO table and Invoice_No (BELNR) (from step4,a),get Inv_Creator (ERNAM), Inv_Amount(REEWR), Currency (WAERS) from EKBE table when PO History cat (Hct-EKBE) is equal to “Q”
    6.     For the corresponding PO number (EBELN) from EKKO table and invoice No (BELNR) from EKBE, get the Reference Document Number (XBLNR) from RSEG table.
    for this i have written
    select ebeln bukrs lifnr zname1 aedat ernam
                                          from
                                          ekko into
                                          table itab_ekko
                                          where bukrs = p_bukrs
                                          AND   lifnr IN so_lifnr
                                          AND   aedat IN so_aedat
                                          AND   ekgrp IN so_ekgrp
                                          AND   ernam IN so_ernam.
      IF NOT itab_ekko[] IS INITIAL.
        SELECT ebeln  ebelp txz01 FROM ekpo into  TABLE
                        itab_ekpo
                        FOR ALL ENTRIES IN  itab_ekko
                        WHERE ebeln = itab_ekko-ebeln.
      ENDIF.
       IF NOT itab_ekko[] IS INITIAL.
        SELECT ebeln budat   FROM ekbe into  TABLE
                        itab_ekbe
                        FOR ALL ENTRIES IN  itab_ekko
                        WHERE ebeln = itab_ekko-ebeln
                              AND bewtp = 'E'
                              AND bewtp = 'Q'.
      ENDIF.
      SORT itab_ekbe by budat.
      read table itab_ekbe index 1."to get first invoice posting date.
    please halp me in completing remaining code

    Hi
    select ebeln bukrs lifnr zname1 aedat ernam
    from
    ekko into
    table itab_ekko
    where bukrs = p_bukrs
    AND lifnr IN so_lifnr
    AND aedat IN so_aedat
    AND ekgrp IN so_ekgrp
    AND ernam IN so_ernam.
    IF NOT itab_ekko[] IS INITIAL.
    SELECT ebeln ebelp txz01 FROM ekpo into TABLE
    itab_ekpo
    FOR ALL ENTRIES IN itab_ekko
    WHERE ebeln = itab_ekko-ebeln.
    ENDIF.
    IF NOT itab_ekko[] IS INITIAL.
    SELECT ebeln budat FROM ekbe into TABLE
    itab_ekbe
    FOR ALL ENTRIES IN itab_ekko
    WHERE ebeln = itab_ekko-ebeln
    AND bewtp = 'E'
    AND bewtp = 'Q'.
    ENDIF.
    SORT itab_ekbe by budat.
    read table itab_ekbe with key HCT = 'E'."to get first GR posting date.
    loop at itab_ekbe where HCT = 'Q'.
    addped itab_ekbe to temp_itab_ekbe.
    endloop.
    read table temp_itab_ekbe index 1. " to get first invoice posting date
    if itab_ekbe-budat < temp_itab_ekbe-budat.
    exit.
    endif.
    *point 5
    select ERNAM REEWR WAERS from EKBE
    into corresponding fields of table i_temp1_ekbe
    for all entries in itab_ekko
    where ebeln = itab_ekko-ebeln.
    loop at i_temp1_ekbe.
    loop at temp_itab_ekbe where ebeln = i_temp1_ekbe-ebeln and
                        belnr = i_temp1_ekbe-belnr.
    if sy-subrc <> 0.
    delete i_temp1_ekbe.
    endif.
    endloop.
    endloop.
    *Point 6
    select XBLNR form rseg
    into corresponding fields of table itab_rseg
    for all entries in i_temp1_ekbe
    where ebeln = i_temp1_ekbe-ebeln and
          belnr = i_temp1_ekbe-belnr.
    regards
    Aditya

  • SQL select statement help

    Say i have a table that has the following fields...
    ID    field1    field2   field3  field4   field5   field6   field7
     1        1           2         E         NW     SW  
         n         n
     2        1           2         E         NE      SW  
         n          n 
     3        1           3         W        NE      SE  
          n          n 
    10,000 plus entries in this table:  it is state quarter quarter data if it helps... 
    So i was handed a list on paper that has about 500 of these quarters from the above said table but there is no ID. I am having a someone build an excel spread
    sheet in the fashion above but the only fields will be as follows
    ID(NOT THE SAME AS ABOVE)  field1   field2  field3 field4  field5
    1                                                  
    1           1         W      NW    NE
     500 or so entries in this table
    no field 6 or 7
    how would i go about selecting all the fields from the top table that match exactly fields 1-5 in the excel sheet?
    and no there are no duplicate entries in the top table.
    thanks,
    james
    dogdaynoon

    Is field6 and field7 nullable fields in yourtable?
    If yes you can simply ignore them in your insert statements
    If you're directly dumping the contents of excel to table then it would be like
    INSERT YourTable (field1,field2,field3,field4,field5)
    SELECT field1,field2,field3,field4,field5
    FROM OPENROWSET(....) AS f
    if you're populating a tsgaing table you can do like this
    INSERT YourTable (field1,field2,field3,field4,field5)
    SELECT field1,field2,field3,field4,field5
    FROM StagingTable s
    Please Mark This As Answer if it solved your issue
    Please Mark This As Helpful if it helps to solve your issue
    Visakh
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to use case to replace the & in select statement

    Oracle version : 11.1.0.6.0
    RHEL
    Hi,
    I want to get a list of all expired and locked users but want to replace the "&" with and here is my code but it isn't working.
    Please some guidance, thanks.
    SQL> select username,
    2 case (account_status like 'EXP%' then 'EXPIRED AND LOCKED'
    3 ELS 'no locked users'
    4 end) account_status
    5 from dba_users
    6 where account_status like 'EXPI%';
    case (account_status like 'EXP%' then 'EXPIRED AND LOCKED'
    ERROR at line 2:
    ORA-00907: missing right parenthesis

    798188 wrote:
    thanks for the comments I corrected the ELSE and 'EPX%' but still same error :
    EOH> select username,
    2 case (account_status like 'EXP%' then 'EXPIRED AND LOCKED'
    3 ELSE 'no locked users'
    4 end) account_status
    5 from dba_users
    6 where account_status like 'EXP%';
    case (account_status like 'EXP%' then 'EXPIRED AND LOCKED'
    ERROR at line 2:
    ORA-00907: missing right parenthesisFirst of all, you do not need a CASE statement.
    Did you see the where clause of your query??
    6 where account_status like 'EXP%';do you realise that your query will always return those records for which value of account_status column starts with 'EXP'?
    Why use CASE when it could be simply written like this :
    SELECT username,
           'EXPIRED AND LOCKED'
    FROM   dba_users
    WHERE  account_status LIKE 'EXP%'

Maybe you are looking for

  • Problem in  set and get values in h:selectBooleanCheckbox with h:datatabel

    hello friends, Please help me any one...i need urgent......................... My jsf page: <h:panelGroup>                               <h:panelGrid columns="6">                               <h:dataTable border="2" value="#{planGroup.screenFlowValu

  • My itunes will not connect to the internet for some reason,

    i can go to the itunes store but when i try to update my iphone it tells me i am not connected to the internet whats going on? anyone have any idea?

  • Doubts in tax master...

    Dear All,               I have some doubts in Tax Master, When I want to view the one customer condition record number(KSCHL) it should display the Tax details, I get the KSCHL from A504, based on the KSCHL I wan to get the tax details from KONP tabl

  • Satellite Pro A300 PSAGDE re-booting when plugged in

    I have had this laptop put away for a while as I couldn't work through this problem, but I'm having another try. The laptop is a Satellite Pro A300 PSAGDE. The problem I am haiving is that the laptop would re-boot whenever I connect the PSU, but not

  • What exactly is the Verizon CD for

    We received a CD when we signed up for DSL. I am just wondering exactly what the purpose of this disk is?