Having Clause In Discoverer

Hi All,
Current I am working on a Discoverer report modification,
Curent report query i ahve taken from View-Sql Inspector that is mentioned below(Sample).
Here i wanted to change the Having condition of the below query through the discoverer tool.
Can any one help me in this regard?
SELECT (bolinf.xxbt_disco_common_pkg.get_sitelevel_coll (o222236.customer_number)) AS c_18
, o222241.segment1 || '-' || o222241.segment2 || '-' || o222241.segment3 || '-' || o222241.segment4 || '-' || o222241.segment5 || '-' || o222241.segment6 || '-' || o222241.segment7 || '-'
|| o222241.segment8 || '-' || o222241.segment9 || '-' || o222241.segment10 AS c_19
,bolinf.xxbt_disco_common_pkg.get_rev_lob (o222245.gl_id_rev) AS c_22
, (bolinf.xxbt_disco_common_pkg.get_siebel_account_code (o222245.gl_id_rev)) AS c_3
, (bolinf.xxbt_disco_common_pkg.get_siebel_account_name (o222245.gl_id_rev)) AS c_4
,o222246.city AS e222753
,o222236.customer_category_code AS e222864
,o222236.customer_class_code AS e222869
,o222236.customer_name AS e222881
,o222236.customer_number AS e222885
,o222239.due_date AS e222988
,o222245.fob_point AS e223035
,o222239.invoice_currency_code AS e223477
,o222236.profile_class_name AS e223794
,o222239.staged_dunning_level AS e224084
,o222239.trx_date AS e224181
,o222239.trx_number AS e224185
,SUM (CASE
FROM ar.ar_collectors o222235
,apps.ar_customers_v o222236
,apps.ar_payment_schedules o222239
,gl.gl_code_combinations o222241
,ar.hz_cust_acct_sites_all o222243
,ar.hz_cust_site_uses_all o222245
,ar.hz_locations o222246
,ar.hz_party_sites o222247
,ar.ra_cust_trx_line_gl_dist_all o222251
, (SELECT lv.lookup_type
,lv.lookup_code
,lv.meaning
,lv.enabled_flag
,lv.start_date_active
,lv.end_date_active
FROM fnd_lookup_values lv
WHERE lv.LANGUAGE = USERENV ('LANG')
AND lv.view_application_id = 222
AND lv.security_group_id = 0
AND lv.lookup_type = 'INV/CM') o410858
,ar.hz_customer_profiles o415961
, (SELECT crm.customer_id
,crm.primary_flag
,crm.site_use_id
,rm.NAME "Payment Method Name"
,haou.NAME
,l_cat.meaning "Account Manager"
FROM ra_cust_receipt_methods crm
,ar_receipt_methods rm
,hz_cust_site_uses_all hcs
,hz_cust_acct_sites_all hcasa
,hr_all_organization_units haou
,ar_lookups l_cat
WHERE crm.receipt_method_id = rm.receipt_method_id(+)
AND hcs.site_use_id = crm.site_use_id
AND haou.organization_id = hcs.org_id
AND hcasa.cust_account_id = crm.customer_id
AND hcasa.cust_acct_site_id(+) = hcs.cust_acct_site_id
AND hcasa.customer_category_code = l_cat.lookup_code(+)
AND l_cat.lookup_type(+) = 'ADDRESS_CATEGORY'
AND haou.NAME NOT LIKE '%OLD%') o681593
WHERE ( (o222236.customer_id = o222239.customer_id)
AND (o222241.code_combination_id = o222251.code_combination_id)
AND (o222243.cust_acct_site_id(+) = o222245.cust_acct_site_id)
AND (o222245.site_use_id(+) = o222239.customer_site_use_id)
AND (o222246.location_id(+) = o222247.location_id)
AND (o222247.party_site_id(+) = o222243.party_site_id)
AND (o222251.customer_trx_id(+) = o222239.customer_trx_id)
AND (o410858.lookup_code = o222239.CLASS)
AND (o222235.collector_id = o415961.collector_id)
AND (o415961.cust_account_id = o222236.customer_id)
AND (o681593.site_use_id = o222245.site_use_id)
AND (o415961.site_use_id IS NULL)
AND (o222251.account_set_flag(+) = 'N')
AND o222239.trx_number ='29801276'
--AND (o222235.NAME = :"Collector Name")
--AND (o222236.profile_class_name = :"Profile Class Name")
--AND (( o222236.customer_category_code = :"Customer Category"
-- OR :"Customer Category" IS NULL))
--AND (( o222236.customer_class_code = :"Customer Class"
-- OR :"Customer Class" IS NULL))
--AND (o222239.invoice_currency_code = :"Currency")
AND ((DECODE ('Y', 'Y', NVL (o222239.amount_due_remaining * NVL (o222239.exchange_rate, 1), 0), NVL (o222239.amount_due_remaining, 0))) 0)
AND (o222251.account_class(+) = 'REC')
GROUP BY (bolinf.xxbt_disco_common_pkg.get_sitelevel_coll (o222236.customer_number))
, o222241.segment1 || '-' || o222241.segment2 || '-' || o222241.segment3 || '-' || o222241.segment4 || '-' || o222241.segment5 || '-' || o222241.segment6 || '-' || o222241.segment7 || '-'
|| o222241.segment8 || '-' || o222241.segment9 || '-' || o222241.segment10
,bolinf.xxbt_disco_common_pkg.get_rev_lob (o222245.gl_id_rev)
, (bolinf.xxbt_disco_common_pkg.get_siebel_account_code (o222245.gl_id_rev))
, (bolinf.xxbt_disco_common_pkg.get_siebel_account_name (o222245.gl_id_rev))
,o222246.city
,o222236.customer_category_code
,o222236.customer_class_code
,o222236.customer_name
,o222236.customer_number
,o222239.due_date
,o222245.fob_point
,o222239.invoice_currency_code
,o222236.profile_class_name
,o222239.staged_dunning_level
,o222239.trx_date
,o222239.trx_number
,o410858.meaning
,o681593.primary_flag
,o681593."Payment Method Name"
,o681593."Account Manager"
HAVING ((((SUM (CASE
WHEN (TO_DATE ('30-APR-2011', 'DD-MON-YYYY') - o222239.due_date) BETWEEN 1 AND 30 THEN (DECODE ('Y'
,'Y', NVL (o222239.amount_due_remaining * NVL (o222239.exchange_rate, 1), 0)
,NVL (o222239.amount_due_remaining, 0)
ELSE 0
END)
+ (SUM (CASE
WHEN (TO_DATE ('30-APR-2011', 'DD-MON-YYYY') - o222239.due_date) BETWEEN 31 AND 60 THEN (DECODE ('Y'
,'Y', NVL (o222239.amount_due_remaining * NVL (o222239.exchange_rate, 1), 0)
,NVL (o222239.amount_due_remaining, 0)
ELSE 0
END)
+ (SUM (CASE
WHEN (TO_DATE ('30-APR-2011', 'DD-MON-YYYY') - o222239.due_date) BETWEEN 61 AND 90 THEN (DECODE ('Y'
,'Y', NVL (o222239.amount_due_remaining * NVL (o222239.exchange_rate, 1), 0)
,NVL (o222239.amount_due_remaining, 0)
ELSE 0
END)
+ (SUM (CASE
WHEN (TO_DATE ('30-APR-2011', 'DD-MON-YYYY') - o222239.due_date) BETWEEN 91 AND 120 THEN (DECODE ('Y'
,'Y', NVL (o222239.amount_due_remaining * NVL (o222239.exchange_rate, 1), 0)
,NVL (o222239.amount_due_remaining, 0)
ELSE 0
END)
+ (SUM (CASE
WHEN (TO_DATE ('30-APR-2011', 'DD-MON-YYYY') - o222239.due_date) BETWEEN 121 AND 150 THEN (DECODE ('Y'
,'Y', NVL (o222239.amount_due_remaining * NVL (o222239.exchange_rate, 1), 0)
,NVL (o222239.amount_due_remaining, 0)
ELSE 0
END)
+ (SUM (CASE
WHEN (TO_DATE ('30-APR-2011', 'DD-MON-YYYY') - o222239.due_date) BETWEEN 151 AND 180 THEN (DECODE ('Y'
,'Y', NVL (o222239.amount_due_remaining * NVL (o222239.exchange_rate, 1), 0)
,NVL (o222239.amount_due_remaining, 0)
ELSE 0
END)
+ (SUM (CASE
WHEN (TO_DATE ('30-APR-2011', 'DD-MON-YYYY') - o222239.due_date) BETWEEN 181 AND 365 THEN (DECODE ('Y'
,'Y', NVL (o222239.amount_due_remaining * NVL (o222239.exchange_rate, 1), 0)
,NVL (o222239.amount_due_remaining, 0)
ELSE 0
END)
+ (SUM (CASE
WHEN (TO_DATE ('30-APR-2011', 'DD-MON-YYYY') - o222239.due_date) < 1 THEN (DECODE ('Y'
,'Y', NVL (o222239.amount_due_remaining * NVL (o222239.exchange_rate, 1), 0)
,NVL (o222239.amount_due_remaining, 0)
ELSE 0
END)
) <> 0
ORDER BY e222881 ASC;

Duplicate post -- Having Clause In Discoverer

Similar Messages

  • Is it possible to achieve Group By....Having functionality in Discoverer?

    Hello All,
    I need to print amount due for each customer when it is negative (less than zero). i.e. sum of all transactions against the customer should be less than zero. This is simple through sql if we write "select sum(amount) group by customer having sum(amount) < 0".
    But I need to do this in discoverer. Now the issue is I need to pass two parameters at runtime. First one will be Date (<= as_of_date) and another one will be having multiple values (in clause).
    If I base my report on underlying report view which uses 'group by... having' sql as described above, I will have to use parameter sheet and use syscontext to pass parameters.
    Instead, it will be easier if i pull in all the data in discoverer report and then use parameters to filter it out. But then is there any way to group on customer and having clause to print only those customers where sum(amount) < 0?
    Anish

    Hi Russ,
    I am new to discoverer so pardon me if I am not able to get you quickly.
    I am sorry, but I did not get you when you say calc1 = SUM( CASE WHEN amount <0 then amount ELSE 0 END).
    May be I was not able to describe you problem. Below is the SQL statement that will give me desired results. I want to achieve same results in Discoverer by getting rid of outer select query with grouping. I will be passing org_id and GL date as parameters.
    select customer_number, name, sum(amount_due) Amount_Due, org_id, Business_Segment
    from
    SELECT hca.account_number customer_number, hp.party_name NAME,
    aps.trx_number, aps.gl_date,
    aps.amount_due_remaining amount_due, aps.class, aps.org_id org_id
    ,hca.attribute3
    FROM apps.ar_payment_schedules_all aps,
    apps.hz_cust_accounts hca,
    apps.hz_parties hp
    WHERE aps.org_id IN (570, 573)
    AND aps.gl_date <= '30-NOV-2008'
    AND aps.class in ('CM','INV','DM')
    AND aps.customer_id = hca.cust_account_id
    AND hca.party_id = hp.party_id
    group by customer_number, name,org_id, Business_Segment
    having sum(amount_due) < 0
    order by 1
    Hope I am able to explain you now.
    Thanks,
    Anish

  • Why Scalar Subquery expression cannot be used in HAVING clauses?

    Hi All,
    I'm new to SQL. I'm confused with Scalar Subquery.
    Is there anyone who can answer me why Scalar Subquery expression cannot be used in HAVING clauses.
    Can you show me a example?
    Thanks very much,
    Xianyi.Ye
    Edited by: 908428 on 2012-1-16 下午7:24

    Hi,
    908428 wrote:
    Hi Frank,
    Thank you for your quick reply. I also agree with your point.
    But when I read the book, "OCA Oracle Database SQL Certified Expert Exam Guide",( link to illegal copies of book removed by moderator )
    on Page 359, it said that
    Scalar subquery expressions cannot be used in the following locations:
    1. In CHECK constraints
    2. In GROUP BY clauses
    3. In HAVING clauses
    4. In a function-based index (which is coming up in Chapter 11)
    5. As a DEFAULT value for a column
    6. In the RETURNING clause of any DML statement
    7. In the WHEN conditions of CASE
    8. In the START WITH and CONNECT BY clauses, which we discuss in
    Chapter 16.7 and 8 are wrong. Scalar sub-queries can be used in WHEN conditions and START WITH and CONNECT BY clauses. (At least in Oracle 10.2. Is the book based on some earlier version?)
    Edited by: BluShadow on 17-Jan-2012 09:08

  • Urgent Group by Having Clause Fails in Oracle and Works in Sybase

    Hello EveryBody I need to select curve data of curve whose date is maximum in that curve so say if i ahve
    so if records are
    curveid curvename curvedate
    1001 test1 12/12/1003
    1001 test1 12/13/1003
    1002 test2 12/12/2002
    1002 test2 12/12/2004
    I have query which run well in sybase but oracle screw up...My logic say having clause is use to filter the records of group so it should have worked in oracle.....
    Here is query
    select curveid,curvename from curve group by curveid having curvedate =max(curve_date)
    This give "not a Group by " error in oracle....It work well in sybase...
    ORA-00979: not a GROUP BY expression
    I have query which use subquery to select these records but i don't want that to use that query
    Please help

    please understand what I need the result
    for each curve i need that data of that curve who date is max in that curve group
    so say for 1001 there are two date 1/1/2001 and 1/1/2002
    I need the data of curve 1001 with date 1/1/2002
    Oracle should have some alternative solution for this....
    If i have to use subquery I do have subquery
    select a.curveid, b.curvename from curve a group by curveid having curvedate = (select max(curvedate) from curve where a.curveid=b.curveid group by curveid );
    I don't want to use that ,,,
    I want to solve my probelm using having and group/....
    Main purpose of having is to filter the records from group result so IT SHOULD DO THAT WHY ORACLE GIVE ORA ERROR FOR
    group by curve_id having curve_date=max(curve_date)
    Creators of oracle please reply

  • Which two statements are true about WHERE and HAVING clause ?

    Which two statements are true about WHERE and HAVING clause ?
    1. WHERE clause can be used to restict rows only
    2.HAVING clause can be used to restrict groups only
    3.HAVING clause can be used to restrict groups and rows
    Plz help me in dis ques...which two will be correct...i think its 1 and 2...but not sure.

    863180 wrote:
    Plz help me in dis ques...which two will be correct...i think its 1 and 2...but not sure.If you are not sure then you do not fully understand HAVING.
    SY.

  • Use of Where and having clause

    Hi all,
    I always have a doubt about use of HAVING and WHERE clause,
    suppose I have table T1 with only one column C1
    CREATE TABLE T1
    (C1 VARCHAR2(1) );
    which having data by following INSERT scripts
    INSERT INTO T1 VALUES('A');
    INSERT INTO T1 VALUES('B');
    INSERT INTO T1 VALUES('C');
    INSERT INTO T1 VALUES('A');
    INSERT INTO T1 VALUES('B');
    INSERT INTO T1 VALUES('A');
    Now I want result as follows
    C1 ==== COUNT(C1)
    ==============
    B ===== 2
    A ===== 3
    So out of query 1 and 2 which approach is right ?
    1) SELECT C1,COUNT(C1) FROM T1
    WHERE C1<>'C'
    GROUP BY C1
    ORDER BY C1 DESC;
    2) SELECT C1,COUNT(C1) FROM T1
    GROUP BY C1
    HAVING C1<>'C'
    ORDER BY C1 DESC;
    Edited by: user13306874 on Jun 21, 2010 2:36 AM

    In SQL, it's always best to filter data at the earliest moment possible.
    In your example the WHERE clause would be that moment:
    SQL> explain plan for
      2  select c1,count(c1)
      3  from t1
      4  where c1 != 'C'
      5  group by c1
      6* order by c1 desc;
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 3946799371
    | Id  | Operation          | Name | Rows  | Bytes |
    |   0 | SELECT STATEMENT   |      |     5 |    10 |
    |   1 |  SORT GROUP BY     |      |     5 |    10 |
    |*  2 |   TABLE ACCESS FULL| T1   |     5 |    10 |
    Predicate Information (identified by operation id):
       2 - filter("C1"!='C')
    18 rows selected.
    SQL>As you can see the filter is applied during the scan of T1.
    Whereas in the HAVING case:
    SQL> explain plan for
      2  select c1,count(c1)
      3  from t1
      4  group by c1
      5  having c1 != 'C'
      6* order by c1 desc;
    Explained.
    SQL> select * from table(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 3146800528
    | Id  | Operation           | Name | Rows  | Bytes |
    |   0 | SELECT STATEMENT    |      |     6 |    12 |
    |*  1 |  FILTER             |      |       |       |
    |   2 |   SORT GROUP BY     |      |     6 |    12 |
    |   3 |    TABLE ACCESS FULL| T1   |     6 |    12 |
    Predicate Information (identified by operation id):
       1 - filter("C1"!='C')
    18 rows selected.
    SQL>The scan is done after all groups have been computed: one of which was computed in vain, since it will be filtered away due to the HAVING clause.
    In general I would use as a guideline: if you are not using aggregate functions in your HAVING clause predicate, then move that predicate to the WHERE portion of your query.
    Edited by: Toon Koppelaars on Jun 21, 2010 11:54 AM

  • Select stmts with Having Clause

    Hi,
    Can some body help me to improve the performance of the below query...
    select t.seq_no,t.contract_id,t.date_from from test_plan_tab t
    group by t.seq_no,t.contract_id,t.date_from
    having (select count(*)
    from test_plan_tab p
    where p.contract_id = t.contract_id
    and p.date_from = t.date_from) > 1
    The having clause will reduce the performance of the above query I guess...
    Thanks And Best Regards,
    /Dinesh...

    If Seq_no is unique then try this
    SELECT MIN(t.seq_no),contract_id,t.date_from,count(*) from test_plan_tab t
    group by t.contract_id,t.date_from
    HAVING COUNT(*) > 1or
    you can try as fsitja said, but you can omit the group by as the partition has already been done on grouping columns
    SELECT seq_no, contract_id, date_from
      FROM (SELECT t.seq_no, t.contract_id, t.date_from, COUNT(*) over(PARTITION BY contract_id, date_from) tot
              FROM test_plan_tab t)
    WHERE tot > 1Regards,
    Prazy

  • Use of group by and having clause

    hi frnds
    can anybody explain me the use of group by an having clause in select state ment

    Hi Rohit,
    1. GROUP BY f1 ... fn
    2. GROUP BY (itab)
    1. GROUP BY f1 ... fn
    Effect
    Groups database table data in a SELECT command on one line in the result set. A group is a set of lines which all have the same values in each column determined by the field descriptors f1 ... fn.
    ... GROUP BY f1 ... fn always requires a list in the SELECT clause. If you use field descriptors without an aggregate funciton in the SELECT clause, you must list them in the GROUP BY f1 ... fn clause.
    Example
    Output the number of passengers, the total weight and the average weight of luggage for all Lufthansa flights on 28.02.1995:
    TABLES SBOOK.
    DATA:  COUNT TYPE I, SUM TYPE P DECIMALS 2, AVG TYPE F.
    DATA:  CONNID LIKE SBOOK-CONNID.
    SELECT CONNID COUNT( * ) SUM( LUGGWEIGHT ) AVG( LUGGWEIGHT )
           INTO (CONNID, COUNT, SUM, AVG)
           FROM SBOOK
           WHERE
             CARRID   = 'LH'       AND
             FLDATE   = '19950228'
           GROUP BY CONNID.
      WRITE: / CONNID, COUNT, SUM, AVG.
    ENDSELECT.
    Note
    ... GROUP BY f1 ... fn is not supported for pooled and cluster tables.
    2. GROUP BY (itab)
    Effect
    Works like GROUP BY f1 ... fn if the internal table itab contains the list f1 ... fn as ABAP source code. The internal table itab can only have one field. This field must be of the type C and should not be more than 72 characters long. itab must be enclosed in parentheses and there should be no blanks between the parentheses and the table name.
    Note
    The same restrictions apply to this variant as to GROUP BY f1 ... fn.
    Example
    Output all Lufthansa departure points with the number of destinations:
    TABLES: SPFLI.
    DATA:   BEGIN OF WA.
              INCLUDE STRUCTURE SPFLI.
    DATA:     COUNT TYPE I.
    DATA:   END OF WA.
    DATA:   WA_TAB(72) TYPE C,
            GTAB LIKE TABLE OF WA_TAB,
            FTAB LIKE TABLE OF WA_TAB,
            COUNT TYPE I.
    CLEAR: GTAB, FTAB.
    WA_TAB = 'COTYFROM COUNT( * ) AS COUNT'. APPEND FTAB.
    APPEND WA_TAB TO FTAB.
    WA_TAB = 'CITYFROM'.
    APPEND WA_TAB TO GTAB.
    SELECT DISTINCT (FTAB)
           INTO CORRESPONDING FIELDS OF WA
           FROM SPFLI
           WHERE
             CARRID   = 'LH'
           GROUP BY (GTAB).
      WRITE: / WA-CITYFROM, WA-COUNT.
    ENDSELECT.
    Regards,
    Susmitha

  • Having clause with Analytic function

    can you pls let me know if we can use HAVING clause with analytic function
    select eid,empno,sum(sal) over(partition by year)
    from employee
    where dept = 'SALES'
    having sum(sal) > 10000I m getting error while using the above,
    IS that we can use HAVING clause with partition by
    Thanks in advance

    Your having clause isn't using an analytical function, is using a regular aggregate function.
    You also can't use analytical functions in the where clause or having clause like that as they are windowing functions and belong at the top of the query.
    You would have to wrap the query to achieve what you want e.g.
    SQL> ed
    Wrote file afiedt.buf
      1  select deptno, total_sal
      2  from (
      3        select deptno,sum(sal) over (partition by deptno) as total_sal
      4        from   emp
      5       )
      6  group by deptno, total_sal
      7* having total_sal > 10000
    SQL> /
        DEPTNO  TOTAL_SAL
            20      10875
    SQL>

  • How can user specify HAVING clause in Interactive Report

    How can user specify HAVING clause in Interactive Report after making the group by selection? Under Actions/Format, the user sees just the Group By-Sort and Group By options.

    Hi ,
    Thanks for your information.
    I am new to the APEX.*i need to show Progress bar while opening the each page* then user can know some process is happening from the backside and i don't know where i need to add and call the below function.could you please provide the steps for the progress bar.
    In my application there are almost 100 pages are there so, i need to show progress bar on each page while opening .could you please provide Global function to call on each page.
    function html_url_Progress(pThis){ 
    $x_Show('AjaxLoading');
    window.setTimeout('$s("AjaxLoading",$x("AjaxLoading").innerHTML)', 100);
    //doSubmit('APPLY_CHANGES');
    redirect(pUrl);
    Regards
    Narender B

  • HAVING clause, or ORDER BY clause ....ERROR

    hi i have following query which throws error plz find the solution for the query to go safe..
    Select C.src_cd,
    D.src_nm,
    count(*) supp_clm_count,
    (CASE WHEN A.clm_ttladjamt > 0 then A.clm_ttladjamt else A.clm_ttlreqamt END) as amount
    From IWOWNER.WC_clm A,
    IWOWNER.WC_clm_srvc B,
    SHOWNER.WC_SRC C,
    SHOWNER.WC_SRC_lang D
    where A.clm_id = B.clm_id
    and A.rcv_loc_id = C.src_id
    and C.src_id = D.src_id
    and TRANSLATE(A.clm_rqst_type_cd) = 'SUPPLIERCLAIM'
    and TRANSLATE(A.clm_typ_cd) in ('WARRANTY','PRE-DELIVERY')
    and DATE(A.clm_create_dt) between '01/01/2000' and '01/01/2010'
    Group by C.src_cd, D.src_nm
    ERROR:
    SQLSTATE: 42803, SQLERRMC: CLM_TTLADJAMT
    Message: An expression starting with "CLM_TTLADJAMT" specified in a SELECT clause, HAVING clause, or ORDER BY clause is not specified in the GROUP BY clause or it is in a SELECT clause, HAVING clause, or ORDER BY clause with a column function and no GROUP BY clause is specified

    Hi,
    With analytic function
    /* Formatted on 2009/07/22 10:47 (Formatter Plus v4.8.8) */
    SELECT DISTINCT c.src_cd, d.src_nm,
                    COUNT (1) OVER (PARTITION BY c.src_cd, d.src_nm)
                                                                   supp_clm_count,
                    SUM (CASE
                            WHEN a.clm_ttladjamt > 0
                               THEN a.clm_ttladjamt
                            ELSE a.clm_ttlreqamt
                         END
                        ) OVER (PARTITION BY c.src_cd, d.src_nm) AS amount
               FROM iwowner.wc_clm a,
                    iwowner.wc_clm_srvc b,
                    showner.wc_src c,
                    showner.wc_src_lang d
              WHERE a.clm_id = b.clm_id
                AND a.rcv_loc_id = c.src_id
                AND c.src_id = d.src_id
                AND a.clm_rqst_type_cd = 'SUPPLIERCLAIM'
                AND a.clm_typ_cd IN ('WARRANTY', 'PRE-DELIVERY')
                AND a.clm_create_dt BETWEEN TO_DATE ('01/01/2000', 'dd/mm/yyyy')
                                        AND TO_DATE ('01/01/2010', 'dd/mm/yyyy')

  • Use CASE in HAVING clause

    I feel like this should be simple but it I'm just not grasping it. 
    Say I have this query:
    SELECT order_number, order_date FROM orders
    I basically want to pull any order from the last 24 hours.  Well this is fairly easy for Tue-Fri but when I run the query on Mon, it will have zero results since there are no orders from the weekend.  If the query is ran on Mon it should query
    Fri instead.
    I'm attempting to use case in my having clause but no luck. 
    HAVING (DATEDIFF(dd, GETDATE(), order_date = (CASE order_date WHEN DATENAME(weekday,getdate()) = 'Friday' THEN '3' ELSE '0' END)
    Sure my syntax or parentheses is way off, any help is appreciated.  Thanks.

    Check out the following CASE expression:
    SELECT CASE WHEN datename(dw,getdate()) = 'Monday' THEN
    CONVERT(DATE,(SELECT dateadd(d, -((datepart(weekday, getdate()) + 1 + @@DATEFIRST) % 7), getdate())))
    ELSE CONVERT(DATE, DATEADD(dd, -1, getdate())) END;
    /********* TEST ****************/
    DECLARE @Dt datetime;
    DECLARE @i int = 0; WHILE (@i < 10) BEGIN
    SET @Dt = dateadd(dd, @i, getdate());
    SELECT Today = @Dt, WeekDay=DATENAME(dw,@Dt), PrevBusinessDay= CASE WHEN datename(dw,@Dt) = 'Monday' THEN
    CONVERT(DATE, (SELECT dateadd(d, -((datepart(weekday, @Dt) + 1 + @@DATEFIRST) % 7), @Dt)))
    ELSE CONVERT(DATE, DATEADD(dd, -1, @Dt)) END;
    SET @i += 1; END -- WHILE
    Today WeekDay PrevBusinessDay
    2014-06-20 19:46:45.130 Friday 2014-06-19
    Today WeekDay PrevBusinessDay
    2014-06-23 19:49:04.817 Monday 2014-06-20
    Today WeekDay PrevBusinessDay
    2014-06-24 19:46:45.130 Tuesday 2014-06-23
    Today WeekDay PrevBusinessDay
    2014-06-25 19:46:45.130 Wednesday 2014-06-24
    Today WeekDay PrevBusinessDay
    2014-06-26 19:46:45.130 Thursday 2014-06-25
    Today WeekDay PrevBusinessDay
    2014-06-27 19:46:45.130 Friday 2014-06-26
    Datetime functions:  
    http://www.sqlusa.com/bestpractices/datetimeconversion/
    Consider also implementation with a calendar table.
    Kalman Toth Database & OLAP Architect
    SQL Server 2014 Design & Programming
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • Group By -- Having Clause related doubt.

    Hello,
    Can we Write/Use rather a 'Having Condition' Before a Group by Clause ..?
    If Yes then How does it Work.. I mean a 'Having' is a WHERE clause (filter) on Aggregate results ...
    SO how does Having works before grouping the Results..??

    Hi,
    Aijaz Mallick wrote:
    Hello,
    Can we Write/Use rather a 'Having Condition' Before a Group by Clause ..?What happens when you try it?
    If Yes then How does it Work.. I mean a 'Having' is a WHERE clause (filter) on Aggregate results ... Right; the HAVING clause is like another WHERE clause.
    The WHERE clause is applied before the GROUP BY is done, and the aggregate functions are computed.
    The HAVING clause is applied after the GROUP BY is done, and the aggregate functions are computed, so you can use aggregate functions in the HAVING clause.
    SO how does Having works before grouping the Results..??The order in which clauses appear in your code isn't necessarily the order in which they are performed. For example,
    SELECT    job
    ,         COUNT (*)  AS cnt
    FROM      scott.emp
    GROUP BY  job;Does it confuse you that this query can reference COUNT (*) in the SLECT clause, which is before the GROUP BY clause?
    The SELECT clause which always comes before the GROUP BY clause in code. That does not mean that the SELECT clause is completed before the GROUP BY clause is begun.
    If the documentation says that clauses must be in a certain order, then use that order, even if your current version of Oracle allows them to be in a different order. There's no guarantee that the next version of Oracle will allow something that was always said to be wrong.

  • How to have Having clause in Group by

    Hi All,
    While using aggregated function (max,min etc) on columns, the SQL generated automatically has the non aggregated columns in the group by clause. How to specify the Having condition ?
    select a , max(b)
    from t
    group by a
    having <condition>
    TIA...

    Hi,
    In your interface drag and drop the source column into canvas for which you want to generate the HAVING clause.
    It will create filters for those columns .Now use aggregation functions like SUM, MAX,MIN, AVG etc in that filter query .
    The code generated will now contain the HAVING clause in it .
    Thanks,
    Sutirtha

  • Subquery in the HAVING Clause

    Hello all,
    i'm getting error when i try to write sub query in having clause. check out my query
    select  ROUND( Count( distinct  Sales2011_DIVDPTA.DIVDPTA_Item_Dept ),0)  AS  "F1" , ROUND( Count( Sales2011.Sales2011_DG1.Item_Season ),0)  AS  "F2"  
    from Sales2011.Sales2011_JT    
      INNER JOIN Sales2011.Sales2011_DG1 On Sales2011.Sales2011_DG1.DG1_ID =Sales2011.Sales2011_JT.DG1_ID   
    LEFT JOIN Sales2011.Sales2011_DIVDPTA On nvl(Sales2011.Sales2011_DIVDPTA.DIVDPTA_ITEM_DIVISION,' ')=nvl(Sales2011.Sales2011_DG1.Item_Division,' ')
      AND  nvl(Sales2011.Sales2011_DIVDPTA.DIVDPTA_ITEM_DEPT,' ')=nvl(Sales2011.Sales2011_DG1.Item_Dept,' ')       
    having ( ROUND( Count( Sales2011.Sales2011_DG1.Item_Season ),0)     in ( 0)
    But it is not executed if I use the sub query in having clause
    select  ROUND( Count( distinct  Sales2011_DIVDPTA.DIVDPTA_Item_Dept ),0)  AS  "F1" ,  ROUND( Count( Sales2011.Sales2011_DG1.Item_Season ),0)  AS  "F2"   
    from Sales2011.Sales2011_JT       
    INNER JOIN Sales2011.Sales2011_DG1 On Sales2011.Sales2011_DG1.DG1_ID =Sales2011.Sales2011_JT.DG1_ID   
    LEFT JOIN Sales2011.Sales2011_DIVDPTA On nvl(Sales2011.Sales2011_DIVDPTA.DIVDPTA_ITEM_DIVISION,' ')=nvl(Sales2011.Sales2011_DG1.Item_Division,' ')
    AND  nvl(Sales2011.Sales2011_DIVDPTA.DIVDPTA_ITEM_DEPT,' ')=nvl(Sales2011.Sales2011_DG1.Item_Dept,' ')        
    having ( ROUND( Count( Sales2011.Sales2011_DG1.Item_Season ),0)
    in ( select   ROUND( Count(
    Sales2011.Sales2011_DG1.Item_Season ),0)  from    Sales2011.Sales2011_DG1 )
    Error at Command Line:1 Column:0
    Error report:
    SQL Error: ORA-00979: not a GROUP BY expression
    00979. 00000 -  "not a GROUP BY expression"
    *Cause:   
    *Action:any help ???

    Sorry unintentionally i have posted my question here.
    will you please elaborate this? Becoz i'm not using group by clause in both query. First query run successfully but as i put sub query in having clause it raised an error. will you tell where i'm committing mistake?
    Aggregates in the HAVING clause do not need to appear in the SELECT list. If the HAVING clause contains a subquery, the subquery can refer to the outer query block if and only if it refers to a grouping column.Edited by: Oracle Studnet on Aug 14, 2011 11:28 PM

Maybe you are looking for

  • Having problems with aperture 3 on imac osx 10.7 and wish to install adobe photoshop elements 10, question will i loose all my liberary from aperture??

    would i loose my fotos from the aperature library when i change to adobe photoshop elements 10. aperture keeps shutting my system down all available help has not done any good.  gmadeline

  • Cannot install itunes AND Apple Mobile Device

    Ok so there is a BIG problem, 3 weeks ago, itunes was working perfectly, and then i got a problem and i had to delete itunes and i also deleted Apple Mobile Device and bonjour and quicktime, but when i try to reinstall itunes, i can't, it just skips

  • Export xml

    Hi everyone I would like to export the xml from my first version of the form I developed and import it to the latest version. The user has completed the old version, so I would like to transfer her information to the new form without her having to fi

  • Re-installing BM 3.8 with NW 6.5.8

    My BM 3.8 server went down. On the replacement server, I installed NW 6.5.8 using the iso disk. When I then tried to re-install BM, the original disk did not recognize the NW 6.5.8 versions of eDir and LDAP, I assume b/c they are too new. I tried usi

  • Client Dies after waking from sleep mode

    On a few machines that have the sleep mode enabled seem to drop connections to the Weblogic server when they wake up. This happens if our Java application is running on the machine without any activity for a while and it goes to sleep. All of the oth