Adding State To Query

Hello -
We have this query and I would like to add the state but wasn't able to.  Please see below and advise how we can edit query so it shows state:
SELECT T0.CreateDate, T0.CardType 'Type', T0.CardCode 'Acct #', T0.CardName 'Company Name',T0.CntctPrsn, T0.Address, T0.City,T0.ZipCode 'Zip', T0.Phone1 'Phone', T0.E_Mail FROM OCRD T0 WHERE T0.CardType in('C','L') and T0.CreateDate >= [%0] and T0.CreateDate <= [%1] ORDER BY T0.ZipCode
Thanks,
Mike

Hello Mike,
Try this one:
SELECT T0.CreateDate, T0.CardType 'Type', T0.CardCode 'Acct #', T0.CardName 'Company Name',T0.CntctPrsn, T0.Address, T0.City,T0.State1, T0.ZipCode 'Zip', T0.Phone1 'Phone', T0.E_Mail
FROM dbo.OCRD T0
WHERE T0.CardType in('C','L') and T0.CreateDate >= [%0\] and T0.CreateDate <= [%1\] ORDER BY T0.State1, T0.ZipCode
Thanks,
Gordon

Similar Messages

  • [Help] statement.executeQuery(query) opens MULTIPLE cursors

    Hey everyone,
    I'm having a real hard time finding anything about this on the net so I've turned here. When we call:
    resultSet = statement.executeQuery(query)
    from a servlet for some reason that one executeQuery opens anywhere from 9-12 cursors in our oracle DB. All the executeQuery documentation I could find just said it should open 1 cursor for that particular ResultSet. query is a fairly simple SQL statement, it searches multiple tables but that doesn't explain why it should open so many cursors.
    On a side note the resultSet and statement are global to the method and are closed in the finally block, no SQLExceptions are thrown further adding to my confusion.
    If anyone has seen something like this where executing 1 query opens multiple cursors please let me know any information you might have.
    Thanks in advance
    -Dave

    Hi Dave
    I had a similar problem using the Oracle 8i, but my query was a more complicated than yours and opened a lot of cursors.
    The answer is to close every ResultSet and the Statement:
    while (xxResult.next()){ ... }
    xxResult.close();
    xxResult.getStatement().close();
    This worked for me,
    Good luck,
    Daniel.

  • Charactersitic values to be used in IFTHEN ELSE STATEMENT IN QUERY

    scenario: i need to use the characteristic values(not the attributes) to be used in an IF THEN ELSE STATEMENT in query. so i created a formula variable for the characteritic of processing type replacement path, replace with key.The values are not fetched in the result and is displayed as X.
    what should i replace with key,lable, constant or other options whereas  my requirement is the all the values present in the characteristc should be used.
    eg. if char name is xyz and has the values 1,2,3,4,5 till -
    20.
    then in a calculated key figure :(formulavariable =1)* kefig1keyfig2 +not(formulavariable =1)kef2keyfig3.
    this formula variable should have all the values of the characteristic values ie 1,2,3---20.
    2. how should i do get the values of characterstics values in the equation give me the steps in detail..
    3. i do not want to use the attributes, though i tried initally while creating the formual variable i replaced with attribute value, there is was an error and there were no reult.
    i tried to create char. variable  for the characteristic  of manual entr , not ready for input values and gave all the values 1,2,3 --20 as default values and then created formaul variable and repalce with the variable, however this characteristic variable is not at all displayed from the list of variables which will be displayed while creating the formula variable.
    help me out.
    Thanks

    hi srini,
    i have includedthe char in rows. i want you to explain in detail how to use these values in the if then else statement in query.
    i have created a calculated key figure 2= (formual variable =1 & keyfig a =0)* keyfig1kefig2 +not(formual variable =1 & keyfig a =0)keyfig2 *calculated keyfig1.
    so this formula variable of replacement path have ref. to then char. and with what value should it replace, key, name, external char or attribut etc so that i should get the values of the char from 1 to20.
    i donot to repalce with the attribute. i just want the char. values and not thier attributes (1. description 2. the second attribute has the values say abc1,efg2,ghi3 for respective charteristic values.
    ie
    char value               desc                 2nd attrib
    1                            hi                     abc1
    2                            bye                  defg2
    3                            ciao                  ghi3

  • Need help with select statement or query

    Not familiar with what to call it, but here is what i need...
    To give our analyst a better idea of warranty on some of our
    equipment, i
    would like to add to the page a column that displays if the
    device is still
    under warranty
    I currently capture the date the equipment was returned from
    repair, so what
    could i use within my select statement or query to display a
    warranty
    expiration date or display on the page...
    example :
    Returned from repair 10/20/2006 warranty expires on
    11/20/2006
    each equipment has different warranties, so i need a formula
    or something to
    say... device #1 has 60 day warranty ( so 10/20/2006 + 60days
    =
    12/19/2006 )
    I would imagine this to be a query
    Table 1 would contain the equipment type and warranty time
    Table 2 would contain the current status of the equipment
    Query would take the back from repair date + warranty =
    expiration date

    Simple. Join the two tables and create a derived column for
    the expiration date. The exact syntax is dependant on your DBMS, so
    check the manual for whichever you are using and look at the date
    functions. There will be a function that will allow you to add a
    number of date units (day, month, year, etc) to a date
    field.

  • XMLQuery starts using XMLSEQUENCEFROMXMLTYPE when adding filter to query

    Hi,
    I'm creating a single XML view on 3 relational tables. These table represent:
    1. a dataset description (table: refs)
    2. a keyset (table: keyset, a table with between refs )
    3. a data set (table: data, consisting of reference to key, value, and reference to a dataset)
    Per dataset I can have multiple keys, per key I have multiple values
    (1:N for dataset:keys, 1:N keys:values)
    The definition is given below:
    DROP TABLE data;
    DROP TABLE refs;
    DROP TABLE keyset;
    CREATE TABLE data (ref int, key int, value float);
    CREATE TABLE refs (ref int);
    CREATE TABLE keyset (key int, ref int);
    CREATE INDEX data_krv ON data (key,ref,value);
    CREATE INDEX keyset_kr ON keyset (key,ref);
    INSERT INTO refs VALUES (1);
    INSERT INTO refs VALUES (2);
    INSERT INTO data VALUES (1,1,1.5);
    INSERT INTO data VALUES (1,1,2.5);
    INSERT INTO data VALUES (1,2,3.5);
    INSERT INTO data VALUES (1,2,4.5);
    INSERT INTO data VALUES (2,1,5.5);
    INSERT INTO data VALUES (2,1,6.5);
    INSERT INTO data VALUES (2,2,7.5);
    INSERT INTO data VALUES (2,2,8.5);
    INSERT INTO keyset SELECT DISTINCT key, ref FROM data;
    CREATE OR REPLACE VIEW drk_xml_view OF XMLType
    with OBJECT ID
      extract(object_value,'/ref').getnumberval()
    AS
    SELECT xmlElement(
         "ref",
         xmlElement("ref_id", refs.ref),
         (SELECT xmlAgg(
                    xmlElement("key",
                      xmlElement("key_id",keyset.key),
                      xmlElement("values",
                          (SELECT xmlAgg(xmlElement("value",data.value))
                           FROM data
                           WHERE data.key=keyset.key AND data.ref=keyset.ref)
          FROM keyset WHERE refs.ref = keyset.ref
    ) FROM refs
    /When I do a query like:
    SELECT xmlQuery('for $i in /ref return max($i/key/values/value)' passing object_value returning content) from drk_xml_view;the explain plan looks as expected:
    | Id  | Operation              | Name      | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT       |           |     2 |    26 |     3   (0)| 00:00:01 |
    |   1 |  SORT AGGREGATE        |           |     1 |    65 |            |          |
    |   2 |   NESTED LOOPS         |           |     1 |    65 |     6   (0)| 00:00:01 |
    |*  3 |    INDEX FAST FULL SCAN| KEYSET_KR |     1 |    26 |     3   (0)| 00:00:01 |
    |*  4 |    INDEX RANGE SCAN    | DATA_KRV  |     1 |    39 |     3   (0)| 00:00:01 |
    |   5 |  SORT AGGREGATE        |           |     1 |       |            |          |
    |   6 |   FAST DUAL            |           |     1 |       |     2   (0)| 00:00:01 |
    |   7 |  TABLE ACCESS FULL     | REFS      |     2 |    26 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       3 - filter("KEYSET"."REF"=:B1)
       4 - access("DATA"."KEY"="KEYSET"."KEY" AND "DATA"."REF"=:B1)
           filter("DATA"."REF"="KEYSET"."REF")
    Note
       - dynamic sampling used for this statementThis is very nicely optimized.
    But now I do this one:
    SELECT xmlQuery('for $i in /ref[./ref_id<2] return max($i/key/values/value)' passing object_value returning content) from drk_xml_view;(where I only added a constraint on the /ref/ref_id) the following occurs:
    | Id  | Operation                          | Name                   | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT                   |                        |     2 |    26 |     3   (0)| 00:00:01 |
    |   1 |  SORT AGGREGATE                    |                        |     1 |     2 |            |          |
    |   2 |   COLLECTION ITERATOR PICKLER FETCH| XMLSEQUENCEFROMXMLTYPE |       |       |            |          |
    |   3 |  SORT AGGREGATE                    |                        |     1 |       |            |          |
    |*  4 |   FILTER                           |                        |       |       |            |          |
    |   5 |    FAST DUAL                       |                        |     1 |       |     2   (0)| 00:00:01 |
    |   6 |  TABLE ACCESS FULL                 | REFS                   |     2 |    26 |     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       4 - filter(:B1<2)
    Note
       - dynamic sampling used for this statementSo, it doesn't use any index any more and creates a XMLSequenceFromXMLType instead. This one is then parsed which results in really bad performance.
    I've tried to add extra indexes to the tables, but that didn't result in an optimilization. From a SQL point of view this seems quite easy, but using the view it gives me problems.
    Is there someone who can explain me what is happening here? Or give me some pointers?
    Please let me know if you need to know more, or if something is unclear.
    Best regards

    SQL> SELECT xmlQuery('for $i in /ref where $i/ref_id < 2 return max($i/key/values/value) ' passing object_value returning content)
      2    from drk_xml_view
      3  /
    XMLQUERY('FOR$IIN/REFWHERE$I/REF_ID<2RETURNMAX($I/KEY/VALUES/VALUE)'PASSINGOBJECT_VALUERETURNINGCONTENT)
    4.5
    Execution Plan
    Plan hash value: 2754328746
    | Id  | Operation           | Name   | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT    |        |     2 |    26 |     2   (0)| 00:00:01 |
    |   1 |  SORT AGGREGATE     |        |     1 |    65 |            |          |
    |*  2 |   HASH JOIN         |        |     1 |    65 |     5  (20)| 00:00:01 |
    |*  3 |    TABLE ACCESS FULL| KEYSET |     1 |    26 |     2   (0)| 00:00:01 |
    |*  4 |    TABLE ACCESS FULL| DATA   |     1 |    39 |     2   (0)| 00:00:01 |
    |   5 |  SORT AGGREGATE     |        |     1 |       |            |          |
    |*  6 |   FILTER            |        |       |       |            |          |
    |   7 |    FAST DUAL        |        |     1 |       |     2   (0)| 00:00:01 |
    |   8 |  TABLE ACCESS FULL  | REFS   |     2 |    26 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access("DATA"."KEY"="KEYSET"."KEY" AND
                  "DATA"."REF"="KEYSET"."REF")
       3 - filter("KEYSET"."REF"=:B1)
       4 - filter("DATA"."REF"=:B1)
       6 - filter(:B1<2)
    Note
       - dynamic sampling used for this statement
    SQL>

  • Adding columns in query causes renames of fields

    Hi All, I'm using Oracle Reports Builder 10g. I have a query which has connections to other queries. When I try to add two columns into that query and recompile the RDF it automatically renames other fields adding "1" at the right side. Any ideas why this is happening? I'm not adding columns with names already existed. Thanks in advance, A. Stoyanov

    Hi, The query is :
    SELECT 0 CUSTOMER_TRX_ID,
           rpad('a', 20, '-') TRX_NUMBER,
           0 TERM_SEQUENCE_NUMBER,
           rpad('a', 40, '-') TRX_TYPE,
           rpad('a', 80, '-') TRX_TYPE_NAME,
           'a' OPEN_RECEIVABLE_FLAG,
           SYSDATE TRX_DATE,
           0 SHIP_TO_CUSTOMER_ID,
           0 SHIP_TO_CONTACT_ID,
           0 REMIT_TO_ADDRESS_ID,
           0 PRIMARY_SALESREP_ID,
           rpad('a', 30, '-') CUSTOMER_NUMBER,
           rpad('a', 240, '-') INTERNAL_NOTES,
           0 BATCH_SOURCE_ID,
           rpad('a', 240, '-') TRX_COMMENTS,
           0 PREVIOUS_CUSTOMER_TRX_ID,
           0 SHIP_TO_SITE_USE_ID,
           0 PRINTING_COUNT,
           SYSDATE PRINTING_ORIGINAL_DATE,
           SYSDATE PRINTING_LAST_PRINTED,
           'a' PRINTING_PENDING,
           0 LAST_PRINTED_SEQUENCE_NUMBER,
           SYSDATE START_DATE_COMMITMENT,
           SYSDATE END_DATE_COMMITMENT,
           0 INITIAL_CUSTOMER_TRX_ID,
           rpad('a', 15, '-') INVOICE_CURRENCY_CODE,
           0 TERM_ID,
           SYSDATE SHIP_DATE_ACTUAL,
           rpad('a', 30, '-') SHIP_VIA,
           rpad('a', 50, '-') WAYBILL_NUMBER,
           rpad('a', 50, '-') PURCHASE_ORDER_NUMBER,
           rpad('a', 50, '-') PURCHASE_ORDER_REVISION,
           SYSDATE PURCHASE_ORDER_DATE,
           SYSDATE TERM_DUE_DATE_FROM_PS,
           0 TERM_RELATIVE_AMOUNT,
           rpad('a', 15, '-') TERM_NAME,
           0 BILL_TO_CUSTOMER_ID,
           0 BILL_TO_CONTACT_ID,
           0 BILL_TO_SITE_USE_ID,
           rpad('a', 40, '-') BILL_TO_LOCATION,
           rpad('a', 360, '-') BILL_CUST_NAME,
           rpad('a', 40, '-') BILL_ADDRESS1,
           rpad('a', 40, '-') BILL_ADDRESS2,
           rpad('a', 40, '-') BILL_ADDRESS3,
           rpad('a', 40, '-') BILL_ADDRESS4,
           rpad('a', 60, '-') BILL_CITY,
           rpad('a', 60, '-') BILL_STATE,
           rpad('a', 60, '-') BILL_POSTAL_CODE,
           rpad('a', 60, '-') BILL_COUNTRY,
           rpad('a', 50, '-') BILL_SITE_TAX_REFERENCE,
           rpad('a', 50, '-') BILL_CUST_TAX_REFERENCE,
           0 TRX_LINE_AMOUNT,
           0 TRX_TAX_AMOUNT,
           0 TRX_FREIGHT_AMOUNT,
           0 TRX_ALL_AMOUNT,
           rpad('a', 360, '-') ORDER_BY,
           rpad('a', 240, '-') BILL_TO_ADDRESS1,
           rpad('a', 240, '-') BILL_TO_ADDRESS2,
           rpad('a', 240, '-') BILL_TO_ADDRESS3,
           rpad('a', 240, '-') BILL_TO_ADDRESS4,
           rpad('a', 60, '-') BILL_TO_STATE,
           rpad('a', 60, '-') BILL_TO_PROVINCE,
           rpad(‘a’, 150, ‘ - ’) our_ref,,
           rpad(‘a’, 150, ‘ - ’) your_ref
      FROM dual
    WHERE 1 = 2
    UNION ALL &common_query
    The bind variable &common_query is accepting the following sql:
    'SELECT
    ' ||:P_SEL_TRX_ID ||'           
    CUSTOMER_TRX_ID
    ' || :P_SEL_TRX_NUMBER  ||'                 
    TRX_NUMBER
    NVL(TL.SEQUENCE_NUM,1)               
    TERM_SEQUENCE_NUMBER 
    ' || :P_SEL_TRX_TYPE ||' 
    TRX_TYPE
    ,       ' || :P_SEL_TRX_TYPE_NAME||' 
    TRX_TYPE_NAME
    ,       TYPES.ACCOUNTING_AFFECT_FLAG     
    OPEN_RECEIVABLE_FLAG
    ,       ' || :P_SEL_TRX_DATE  ||'       
    TRX_DATE
    ,       SHIP_TO_CUSTOMER_ID                   
    SHIP_TO_CUSTOMER_ID
    ,       SHIP_TO_CONTACT_ID                   
    SHIP_TO_CONTACT_ID
    ,       REMIT_TO_ADDRESS_ID                   
    REMIT_TO_ADDRESS_ID
    ,       A.PRIMARY_SALESREP_ID                 
    PRIMARY_SALESREP_ID
    ,       B.ACCOUNT_NUMBER                     
    CUSTOMER_NUMBER
    ,       A.INTERNAL_NOTES                     
    INTERNAL_NOTES
    A.BATCH_SOURCE_ID
    BATCH_SOURCE_ID
    A.COMMENTS
    TRX_COMMENTS
    ,       PREVIOUS_CUSTOMER_TRX_ID             
    PREVIOUS_CUSTOMER_TRX_ID
    ,       SHIP_TO_SITE_USE_ID                   
    SHIP_TO_SITE_USE_ID
    ,       NVL(PRINTING_COUNT,0)                 
    PRINTING_COUNT
    ,       PRINTING_ORIGINAL_DATE               
    PRINTING_ORIGINAL_DATE
    ,       PRINTING_LAST_PRINTED                 
    PRINTING_LAST_PRINTED
    ,       PRINTING_PENDING                         PRINTING_PENDING
    ,       LAST_PRINTED_SEQUENCE_NUM             LAST_PRINTED_SEQUENCE_NUMBER
    ,       START_DATE_COMMITMENT                    START_DATE_COMMITMENT
    ,       END_DATE_COMMITMENT                      END_DATE_COMMITMENT
    ,       INITIAL_CUSTOMER_TRX_ID                  INITIAL_CUSTOMER_TRX_ID
    ,       A.INVOICE_CURRENCY_CODE                  INVOICE_CURRENCY_CODE
    ,       A.TERM_ID      TERM_ID
    ,       A.SHIP_DATE_ACTUAL                       SHIP_DATE_ACTUAL
    ,       A.SHIP_VIA                                 SHIP_VIA
    ,       A.WAYBILL_NUMBER                        WAYBILL_NUMBER
    ,       A.PURCHASE_ORDER                         PURCHASE_ORDER_NUMBER
    ,       A.PURCHASE_ORDER_REVISION              PURCHASE_ORDER_REVISION
    ,       A.PURCHASE_ORDER_DATE                    PURCHASE_ORDER_DATE
    ,       P.DUE_DATE                                 TERM_DUE_DATE_FROM_PS
    ,       NVL(TL.RELATIVE_AMOUNT,100)* (100/NVL(T.BASE_AMOUNT,100))         TERM_RELATIVE_AMOUNT
    ,       T.NAME                    TERM_NAME
    ,       A.BILL_TO_CUSTOMER_ID                    BILL_TO_CUSTOMER_ID
    ,       A.BILL_TO_CONTACT_ID                     BILL_TO_CONTACT_ID
    ,       A.BILL_TO_SITE_USE_ID                    BILL_TO_SITE_USE_ID
    ,       U_BILL.LOCATION                              BILL_TO_LOCATION
    ,       NVL(A_BILL.TRANSLATED_CUSTOMER_NAME,PARTY.PARTY_NAME)     BILL_CUST_NAME
    ,       RTRIM(RPAD(LOC.ADDRESS1,40))      BILL_ADDRESS1
    ,       RTRIM(RPAD(LOC.ADDRESS2,40) )      BILL_ADDRESS2
    ,       RTRIM(RPAD(LOC.ADDRESS3,40) )     BILL_ADDRESS3
    ,       RTRIM(RPAD(LOC.ADDRESS4,40) )      BILL_ADDRESS4
    ,       LOC.CITY                                BILL_CITY
    ,       NVL(LOC.STATE , LOC.PROVINCE)   BILL_STATE
    ,       LOC.POSTAL_CODE                       BILL_POSTAL_CODE
    ,       LOC.COUNTRY                           BILL_COUNTRY
    ,       U_BILL.TAX_REFERENCE                     BILL_SITE_TAX_REFERENCE
    ,       PARTY.TAX_REFERENCE                          BILL_CUST_TAX_REFERENCE
    ,       ' ||:P_SEL_TRX_LINE_AMOUNT||'        TRX_LINE_AMOUNT
    ,       ' ||:P_SEL_TRX_TAX_AMOUNT ||'              TRX_TAX_AMOUNT
    ,       ' ||:P_SEL_TRX_FREIGHT_AMOUNT||'               TRX_FREIGHT_AMOUNT
    ,       ' ||:P_SEL_TRX_ALL_AMOUNT  ||'               TRX_ALL_AMOUNT
    ,       ' || L_ORDER_BY || '     ORDER_BY
    ,      LOC.ADDRESS1      BILL_TO_ADDRESS1
    ,     LOC.ADDRESS2      BILL_TO_ADDRESS2
    ,      LOC.ADDRESS3      BILL_TO_ADDRESS3
    ,      LOC.ADDRESS4      BILL_TO_ADDRESS4
    ,      LOC.STATE      BILL_TO_STATE
    ,      LOC.PROVINCE      BILL_TO_PROVINCE
    , a.attribute1 as our_ref
    , a.attribute2 as your_ref
    FROM    ' || :P_TABLE1 || '
    WHERE  ' || :P_WHERE1 || '
      ' || :P_USER_WHERE_CLAUSE1 || '
      ' || :P_USER_WHERE_CLAUSE2 || '
      ' || :P_USER_WHERE_CLAUSE3 || '
      ' || :P_MLS_CONDITION || '
      ' || :P_EC_WHERE_CLAUSE || '
            ' || :P_BR_WHERE_CLAUSE || '
            ' || :lp_trx_num_high || '
            ' || :lp_trx_num_low || '
            ' || :lp_trx_date_clause ||'
            ' || :lp_doc_seq_clause|| '
    UNION
    SELECT   ' || :P_SEL_TRX_ID || '
    ,  ' || :P_SEL_TRX_NUMBER || '
    ,  NVL(P.TERMS_SEQUENCE_NUMBER,1)
    ,   ' || :P_SEL_TRX_TYPE || '
    ,  ' || :P_SEL_TRX_TYPE_NAME || '
    ,  TYPES.ACCOUNTING_AFFECT_FLAG
    ,  ' || :P_SEL_TRX_DATE || '
    ,  A.SHIP_TO_CUSTOMER_ID
    ,  A.SHIP_TO_CONTACT_ID
    ,  A.REMIT_TO_ADDRESS_ID
    ,  A.PRIMARY_SALESREP_ID
    ,  B.ACCOUNT_NUMBER
    ,  A.INTERNAL_NOTES
    ,  A.BATCH_SOURCE_ID
    ,  A.COMMENTS
    ,  PREVIOUS_CUSTOMER_TRX_ID
    ,  SHIP_TO_SITE_USE_ID
    ,   NVL(PRINTING_COUNT,0)
    ,  PRINTING_ORIGINAL_DATE
    ,  PRINTING_LAST_PRINTED                
    ,  PRINTING_PENDING                      
    ,  LAST_PRINTED_SEQUENCE_NUM
    ,  START_DATE_COMMITMENT
    ,  END_DATE_COMMITMENT
    ,  INITIAL_CUSTOMER_TRX_ID
    ,  A.INVOICE_CURRENCY_CODE
    ,   A.TERM_ID
    ,   A.SHIP_DATE_ACTUAL
    ,  A.SHIP_VIA
    ,  A.WAYBILL_NUMBER
    ,  A.PURCHASE_ORDER
    ,  A.PURCHASE_ORDER_REVISION
    ,  A.PURCHASE_ORDER_DATE
    ,  P.DUE_DATE
    ,   NVL(TL.RELATIVE_AMOUNT,100)*
                     (100/NVL(T.BASE_AMOUNT,100))
    ,  T.NAME
    ,  A.BILL_TO_CUSTOMER_ID
    ,  A.BILL_TO_CONTACT_ID
    ,   A.BILL_TO_SITE_USE_ID
    ,  U_BILL.LOCATION                            BILL_TO_LOCATION
    ,  NVL(A_BILL.TRANSLATED_CUSTOMER_NAME,PARTY.PARTY_NAME)
                             BILL_CUST_NAME
    ,  RTRIM(RPAD(LOC.ADDRESS1, 40)) 
    ,  RTRIM(RPAD(LOC.ADDRESS2, 40) )                      
    ,   RTRIM(RPAD(LOC.ADDRESS3,  40) )                      
    ,  RTRIM(RPAD(LOC.ADDRESS4 ,  40) )                     
    ,   LOC.CITY                           
    ,  NVL(LOC.STATE , LOC.PROVINCE)                         
    ,   LOC.POSTAL_CODE                    
    ,  LOC.COUNTRY
    ,  U_BILL.TAX_REFERENCE
    ,  PARTY.TAX_REFERENCE
    ,   ' || :P_SEL_TRX_LINE_AMOUNT || '             
    ,  ' || :P_SEL_TRX_TAX_AMOUNT || '                
    ,  ' || :P_SEL_TRX_FREIGHT_AMOUNT  || '     
    ,  ' || :P_SEL_TRX_ALL_AMOUNT || '             
    ,   ' || L_ORDER_BY || '
    ,   LOC.ADDRESS1
    ,  LOC.ADDRESS2
    ,  LOC.ADDRESS3
    ,  LOC.ADDRESS4
    ,  LOC.STATE
    ,  LOC.PROVINCE
    , a.attribute1 as our_ref
    , a.attribute2 as your_ref
    FROM   ' || :P_TABLE2 || '
    WHERE  ' || :P_WHERE2 || '
      ' || :P_USER_WHERE_CLAUSE1 || '
      ' || :P_USER_WHERE_CLAUSE2 || '
      ' || :P_USER_WHERE_CLAUSE3 || '
      ' || :P_MLS_CONDITION || '
      ' || :P_EC_WHERE_CLAUSE || '
            ' || :P_BR_WHERE_CLAUSE || '
            ' || :lp_trx_num_low || '
            ' || :lp_trx_num_high ||'
            ' || :lp_trx_date_clause ||'
            ' || :lp_doc_seq_clause;
    The columns I added are OUR_REF and YOUR_REF which are at the end of the SELECT clause.
    Thanks,
    A.Stoyanov

  • Adding subquery to query w/ Group By clause crashes

    Hello all! I am trying to add in the subquery to the statement below. The query works fine before I add in the subquery, but after adding the subquery it will time out. If I comment out the MIN(table1.EOD_DATE) and the Group By clause, the query works fine.
    I do not want to do this I need those two items. What am I missing here? Any ideas are appreciated, thanks!
    SELECT table1.FUND,
    table1.DEPT,
    table1.ORG,
    table1.ACCT,
    LPAD(table1.FUND,3,0)||LPAD(table1.DEPT,2,0)||LPAD(table1.ORG,4,0)||SUBSTR(table1.ACCT,1,2) acct_no,
    LPAD(table1.FUND,3,0)||LPAD(table1.DEPT,2,0)||LPAD(table1.ORG,4,0)||table1.ACCT acct_no1,
    table2.FUND,
    table2.DEPT,
    table2.ORG,
    table2.ACCT
    MIN(table1.EOD_DATE)
    FROM table1,
    table2
    WHERE table1.fund BETWEEN substr(:P_ACCT_FROM,0,3) AND substr(:P_ACCT_TO,0,3)
    ANDtable1.dept BETWEEN substr(:P_ACCT_FROM,4,2) AND substr(:P_ACCT_TO,4,2)
    ANDtable1.org BETWEEN substr(:P_ACCT_FROM,6,4) AND substr(:P_ACCT_TO,6,4)
    ANDtable1.acct BETWEEN substr(:P_ACCT_FROM,10,5) AND substr(:P_ACCT_TO,10,5)
    AND floor(table1.acct/10000) in (6,8)
    AND SUBSTR(table1.acct,3) != '000'
    ANDtable1.eod_date BETWEEN :p_from_date AND :p_to_date
    AND table2.fund (+)=table1.fund
    AND table2.dept (+)=table1.dept
    AND table2.org (+)=table1.org
    AND table2.acct (+)=table1.acct
    AND table2.type IN( 'PI','JE','PR','VD','VU','AC','AD')
    AND table2.po_no IN
    SELECT trans.po_no
    FROM table2 trans LEFT OUTER JOIN req ON trans.po_no = req.po_no
    WHERE (trans.po_no IS NULL OR (TO_CHAR(req.open_date,'YYYY')) = (TO_CHAR(:p_year,'FM9999')))
    GROUP BY table1.fund,
    table1.dept,
    table1.org,
    table1.acct,
    table2.fund,
    table2.dept,
    table2.org,
    table2.acct
    ORDER BY LPAD(table1.FUND,3,0)||LPAD(table1.DEPT,2,0)||LPAD(table1.ORG,4,0)||SUBSTR(table1.ACCT,1,2),
    LPAD(table1.FUND,3,0)||LPAD(table1.DEPT,2,0)||LPAD(table1.ORG,4,0)||table1.ACCT

    Some untested comments;
    AND floor(table1.acct/10000) in (6,8)
    AND SUBSTR(table1.acct,3) != '000'Can these two conditions be combined, ie is this the same as;
    AND (table1.acct LIKE '0006%' OR table1.acct LIKE '0008%')Ignoring the hard coded dates (assumed they where used for testing) you should avoid using implicit conversions and two digit years;
    AND trans.activity_date BETWEEN TO_CHAR('01-jan-2007', 'dd-mon-yyyy') AND TO_CHAR('01-feb-2007', 'dd-mon-yyyy')You can convert your parameters once rather than converting every row by making hte parameter match the column data type;
    AND (   trans.po_no IS NULL
         OR req.open_date BETWEEN TO_DATE('01-JAN-' || TO_CHAR(:p_year,'9999') || ' 00:00:00' ,'DD-MON-YYYY HH24:MI:SS')
                              AND TO_DATE('31-DEC-' || TO_CHAR(:p_year,'9999') || ' 23:59:59' ,'DD-MON-YYYY HH24:MI:SS')
        )

  • IF statement in Query

    Hi
    I have a query / recordset that  would be looking at 12000 rows in a database and 10 different variables and potential filters chosen by end users.
    Should I put 10 wild card / url Where statements in my recordset query or should I put IF statements in my query.
    ie.
    If URL colname then ",and BetType= "xzz"" .
    Is that the most efficient way to run my queries.
    I will be running about 10 recordsets on my page all looking at these url variables so it will be a busy page.
    If that is the answer can someone please tell me how to insert the if statement - i've tried allsorts but it wont work.
    $colname_Recordset4 = "%";
    if (isset($_GET['colname'])) {
      $colname_Recordset4 = $_GET['colname'];
    mysql_select_db($database_racing_analysis, $racing_analysis);
    $query_Recordset4 = sprintf("SELECT BetType, sum(if(season='2006-2007', Bet, 0)) AS '2006-2007',  sum(if(season='2007-2008', Bet, 0)) AS '2007-2008',  sum(if(season='2008-2009', Bet, 0)) AS '2008-2009' FROM dataextract WHERE BetType Like %s and TrackID = 1 and Distance = 1000 and Class = 1 GROUP BY BetType", GetSQLValueString($colname_Recordset4, "text"));
    $Recordset4 = mysql_query($query_Recordset4, $racing_analysis) or die(mysql_error());
    $row_Recordset4 = mysql_fetch_assoc($Recordset4);
    $totalRows_Recordset4 = mysql_num_rows($Recordset4);
    hope someone can help.
    Simon

    That part of the query cross tabs my data into three columns - not intended to confuse the issue. I'd have the same problem with a basic query.
    So Here is a very basic version:
    I want an IF statement to go around: "WHERE Distance = 1000" and "AND Class = 1"
    That I believe will reduce the effort on the MYSQL Server as it wouldn't be running a bunch of wild card queries and would only run if there is a URL paramter delivered.??
    I just don't get how to put the IF statements in PHP.
    thanks
    $maxRows_Recordset3 = 5;
    $pageNum_Recordset3 = 0;
    if (isset($_GET['pageNum_Recordset3'])) {
      $pageNum_Recordset3 = $_GET['pageNum_Recordset3'];
    $startRow_Recordset3 = $pageNum_Recordset3 * $maxRows_Recordset3;
    mysql_select_db($database_racing_analysis, $racing_analysis);
    $query_Recordset3 = "SELECT * FROM dataextract WHERE Distance = 1000 AND Class = 1";
    $query_limit_Recordset3 = sprintf("%s LIMIT %d, %d", $query_Recordset3, $startRow_Recordset3, $maxRows_Recordset3);
    $Recordset3 = mysql_query($query_limit_Recordset3, $racing_analysis) or die(mysql_error());
    $row_Recordset3 = mysql_fetch_assoc($Recordset3);
    if (isset($_GET['totalRows_Recordset3'])) {
      $totalRows_Recordset3 = $_GET['totalRows_Recordset3'];
    } else {
      $all_Recordset3 = mysql_query($query_Recordset3);
      $totalRows_Recordset3 = mysql_num_rows($all_Recordset3);
    $totalPages_Recordset3 = ceil($totalRows_Recordset3/$maxRows_Recordset3)-1;

  • Adding  values in query for like materials.

    Greetings Gurus,
    I am very new to ABAB. I recently made a query attached to an infoset, that lists the amount received from a purchase order and compares the amount that was ordered (overdelivery allowed). With this I added a custom field and and in the Extras/Code tab I added (for "Record Processing")
    IF MSEG-BPMNG > EKPO-MENGE.
    ZCUSTOMF = 'OVERDELIVERED'.
    ELSE.
    CLEAR CUSTOMFIELD.
    ENDIF.
    This compares the amount received vs the amount ordered and gives a new field value if overdelivery occured. However it occurred that there may be multiple batches of the same material when received. When this happens the query displays multiple lines (same material document number) with each amount and does not add the value of the different batches of the same material. Is there any additional code that could be added that  'When the same material document number and same material' appear more than once to add the quantity received together and view it on one line? Any kind of help (especially with ABAP explanations) at all is greatly appreciated.
    Thank You

    Hi,
    You have to Loop at the itab which you are processing in the same code  tab with looping at itab at the material document you are processing at that moment. then sum up the Qty and Amount at the end of the loop and then check the amounts and then update the custom field for that PO or material document.
    As this code will be repeated for all the items of the document every time when you loop for that specific document just check whether the custom field is empty or not . Process the loop if empty only. As if i t is not empty then it is understood that thsi item has been processed earlier.
    Regards, Shakeel.

  • Pass parameter to sql statement in query manager

    Hai to all,
               I want to pass the percentage  as the parameter into the sql statemnet.i what to execute it in the query manager.
              If i execute that statement then cann't found the tablename error is coming.
             Other than the data in the table (general data)  pass to the parameter in the sql at runtime.
    for example:
    select [%0] *100
    how to pass 10 to that sql statement.
    Please help me...
    Regards,
    Raji.

    Hi Ramya,
    You can create a SP with parameters to accept and then execut this SP from SAP Business One Query Manager by passing the parameter (in your case 10). The result will be as desired.
    Ex:
    Create this Procedure in SQL Management Studio
    create proc Test(@a as int)
    as
    begin
    select (@a*100)
    end
    To Execute the Query use this Query and pass the desired values with parameters
    execute Test 10
    Regards,
    Reno

  • How to pass column name in slect statement in query

    hi,
    i want to make a report where in query select statement using variable as a column name. but its not working plz guide me how can i do this.
    i have created a function which return column name through variable & that variable i want to to use in select statement
    select :m1 from table1;
    regards

    Hi,
    Create a user parameter (say P_field), and assign a valid field name as initial value (say NAME), And In the Query, write
    SELECT CODE, &P_field FN_FIELD FROM <table_name> WHERE <condition>And in the BEFORE PARAMETER FORM Trigger under the Report Triggers, write,
    function BeforePForm return boolean is
    begin
      :P_field := <your_function_call>;
      return (TRUE);
    end;And use that FN_FIELD field in the report.
    Hope this will clear your issue.
    Regards,
    Manu.

  • Adding objects into query Panel and no display report

    Hi Folks,
    I had an issue with WEBI .
    Iam running the report with few objects at first time , all objects are displayed in the  table format of report.
    I saved and closed the report .
    Later  i opened the report and edited the report by adding new objects into query panel and runing it.
    but this time  i did not find the new objects in display table in report as like DeskI.
    If we find the solution for this , it will be great help to me.
    Thanks
    Mahesh

    The objects will be in the data tab. Objects are not automatically added to your report in Webi, they are made available in the data panel, and you can choose which objects to add.

  • Hiding SQL statement in Query Result Window

    Hi everyone,
    Is it possible to hide the SQL statement from a query result window? This can usually be done by click the orange triangle that is positioned to the left of the SQL string box (to expand and collapse it). The System Queries have this box collapsed per default, is it possible to have this setup as default for all queries, including the custom? If so, please let me know where this can be done.
    Cheers

    You should do this only with SDK programming - dont allow to show the syntax. The next, but problematic way, is the code you have do inside stored procedure and call only this sp inside the query generator window - if you have there some input parameters, you should use filling variables before executing sp and get it as input parameters to sp.

  • Extra condition added in the query

    Hi All,
    I have created a report but its not showing all the results.When I checked the query I saw the extra filter (where ( D1.c7 = 1 )) .I have not added any such filter.Can someone please tell me how this filter has got added and how we can avoid OBIEE to add such filter for this report.Below is the query:
    select T203238.ENTITY_TYPE as c1,
    T203238.ENTITY_NAME as c2,
    cast(T183904.DAY as DATE) as c3,
    cast(TO_NUMBER(TO_CHAR(T183904.TO_TIME, 'hh24'), '99') as CHARACTER ( 30 ) ) as c4,
    concat(concat(concat(concat(cast(TO_NUMBER(TO_CHAR(T183904.TO_TIME, 'hh24'), '99') as CHARACTER ( 30 ) ), ':'), cast(TO_NUMBER(TO_CHAR(T183904.TO_TIME, 'mi'), '99') as CHARACTER ( 30 ) )), ':'), cast(TO_NUMBER(TO_CHAR(T183904.TO_TIME, 'ss'), '99') as CHARACTER ( 30 ) )) as c5,
    sum(T203256.USAGE_VALUE) as c6,
    ROW_NUMBER() OVER (PARTITION BY T203238.ENTITY_NAME, T203238.ENTITY_TYPE, cast(T183904.DAY as DATE) ORDER BY T203238.ENTITY_NAME ASC, T203238.ENTITY_TYPE ASC, cast(T183904.DAY as DATE) ASC) as c7
    from
    (Select a.entity_pk_key entity_fk_key,a.Entity_Name Entity_Name,a.Entity_Description Entity_Description,d.meaning Entity_Type,c.plant_name Site_Name, b.System_Name System_Name,a.Production_Entity Production_Entity,a.Business_Function Business_Function,E.MEANING Status from
    ( SELECT EQUIPMENT_PK_KEY ENTITY_PK_KEY,EQUIPMENT_Name Entity_Name, EQUIPMENT_Description Entity_Description,'EQUIPMENT' Entity_Type, plant_fk_key, System_fk_key, PRODUCTION_EQUIPMENT Production_Entity ,
    NULL Business_FUNCTION, STATUS FROM MTC_EQUIPMENTS_D)a
    ) T203238,
    apps.MTC_HOUR_MV T183904 /* Dim_445_Period_Calendar_Hour */ ,
    ( SELECT e.ENTITY_FK_KEY,e.ENTITY_TYPE, Sum(e.USAGE_VALUE) USAGE_VALUE ,avg(e.N_EXT_ATTR1) N_EXT_ATTR1,avg(e.N_EXT_ATTR2) N_EXT_ATTR2, hour_fk_key FROM
    (SELECT ENTITY_FK_KEY,B.MEANING ENTITY_TYPE, USAGE_VALUE ,NULL N_EXT_ATTR1,NULL N_EXT_ATTR2,hour_fk_key FROM MTH_ENTITY_SUSTAIN_ASPECT A,FND_LOOKUP_VALUES B
    WHERE B.LOOKUP_TYPE IN ('MTH_USER_DEFINED_ENTITIES', 'MTH_OTHER_ENTITY_TYPE')
    AND B.LANGUAGE = USERENV('LANG')
    AND UPPER(A.ENTITY_TYPE)=UPPER(B.LOOKUP_CODE)
    AND METER_CATEGORY ='PRIMARY'
    AND SUSTAIN_ASPECT='ELECTRICITY'
    AND entity_fk_key=1149
    AND hour_fk_key IN(7283,7294,7300,7301,7302,7303,7304,7305,7306,7284,7285,7286,7287,7288,7289,7290,7291,7292,7293,7295,7296,7297,7298,7299)
    )e
    GROUP BY entity_fk_key,entity_type ,hour_fk_key
    ) T203256
    where ( T183904.HOUR_PK_KEY = T203256.HOUR_FK_KEY and T203238.ENTITY_FK_KEY = T203256.ENTITY_FK_KEY and T203238.ENTITY_TYPE = T203256.ENTITY_TYPE )
    group by T203238.ENTITY_NAME, T203238.ENTITY_TYPE, cast(TO_NUMBER(TO_CHAR(T183904.TO_TIME, 'hh24'), '99') as CHARACTER ( 30 ) ), cast(T183904.DAY as DATE), concat(concat(concat(concat(cast(TO_NUMBER(TO_CHAR(T183904.TO_TIME, 'hh24'), '99') as CHARACTER ( 30 ) ), ':'), cast(TO_NUMBER(TO_CHAR(T183904.TO_TIME, 'mi'), '99') as CHARACTER ( 30 ) )), ':'), cast(TO_NUMBER(TO_CHAR(T183904.TO_TIME, 'ss'), '99') as CHARACTER ( 30 ) ))
    ) D1 )
    where ( D1.c7 = 1 )
    Thanks a lot in advance

    No,I am not having any topn or bottomn filters in my query .
    1. I am having entity type and entity name in the report which comes form the view in rpd(view defn:SELECT EQUIPMENT_PK_KEY ENTITY_PK_KEY,EQUIPMENT_Name Entity_Name, EQUIPMENT_Description Entity_Description,'EQUIPMENT' Entity_Type, plant_fk_key, System_fk_key, PRODUCTION_EQUIPMENT Production_Entity ,
    NULL Business_FUNCTION, STATUS FROM MTC_EQUIPMENTS_D) .I
    2. want to see the data at hour level so the hour data comes from apps.MTC_HOUR_MV .
    3. I want to see sum(usage_value) for a entity type,entity name and hour dimension .Sum(usage_value) comes from the view in rpd which has the definition:SELECT e.ENTITY_FK_KEY,e.ENTITY_TYPE, Sum(e.USAGE_VALUE) USAGE_VALUE ,avg(e.N_EXT_ATTR1) N_EXT_ATTR1,avg(e.N_EXT_ATTR2) N_EXT_ATTR2, hour_fk_key FROM
    (SELECT ENTITY_FK_KEY,B.MEANING ENTITY_TYPE, USAGE_VALUE ,NULL N_EXT_ATTR1,NULL N_EXT_ATTR2,hour_fk_key FROM MTH_ENTITY_SUSTAIN_ASPECT A,FND_LOOKUP_VALUES B
    WHERE B.LOOKUP_TYPE IN ('MTH_USER_DEFINED_ENTITIES', 'MTH_OTHER_ENTITY_TYPE')
    AND B.LANGUAGE = USERENV('LANG')
    AND UPPER(A.ENTITY_TYPE)=UPPER(B.LOOKUP_CODE)
    AND METER_CATEGORY ='PRIMARY'
    AND SUSTAIN_ASPECT='ELECTRICITY'
    AND entity_fk_key=1149
    AND hour_fk_key IN(7283,7294,7300,7301,7302,7303,7304,7305,7306,7284,7285,7286,7287,7288,7289,7290,7291,7292,7293,7295,7296,7297,7298,7299)
    )e
    GROUP BY entity_fk_key,entity_type ,hour_fk_key
    this view entity_fk_key and entity_type joins with enity_fk_key and entity_type of entity diemnsion and hour_fk_key joins with hour_pk_key of MV definition.
    I am having entity type,entity name,day,hour,sum(usage_value) in the report
    Thanks a lot for your help

  • Adding Dates To Query

    What I am trying to achieve.
    I have 3 tables.
    tblCUSTDETAILS - Contains Customers Information.
    tblFLTNUMS - Contains Faults The Customer Has
    tblCONTACTS - Contains The Monthly Volume of Contacts by the Customer.
    What I want to do is show the amount of contacts 3 months after the date of the fault. So I can say things like 3 month after a fault the customer still contacts us back as they have lost confidence with our service. etc.
    The problem is that if the customer hasn't called back for a specific month then it doesn't record 0 and this is what I want.
    WITH tblCUSTDETAILS AS (
        SELECT  '11111' AS CUST_ID, 'John Smith' AS CUST_NAME FROM DUAL UNION ALL
        SELECT  '11112' AS CUST_ID, 'Andy Wilson' AS CUST_NAME FROM DUAL
    ), tblFLTNUMS AS (
        SELECT  '11111' AS CUST_ID, TO_DATE('JAN-10', 'MON-YY') AS FLT_DT FROM DUAL UNION ALL
        SELECT  '11112', TO_DATE('FEB-10', 'MON-YY') FROM DUAL UNION ALL
        SELECT  '11112', TO_DATE('APR-10', 'MON-YY') FROM DUAL 
       tblCONTACTS AS (
        SELECT  '11111' AS CUST_ID, TO_DATE('JAN-10', 'MON-YY') AS CONTACT_DT, 5 AS CONTACT_VOL FROM DUAL UNION ALL
        SELECT  '11111', TO_DATE('FEB-10', 'MON-YY'), 3 FROM DUAL UNION ALL
        SELECT  '11112', TO_DATE('MAR-10', 'MON-YY'), 1 FROM DUAL UNION ALL
        SELECT  '11112', TO_DATE('MAY-10', 'MON-YY'), 2 FROM DUAL
    SELECT  t1.cust_id,
            t2.cust_name,
            t1.flt_dt,
            t3.contact_dt,
            t3.contact_vol
    FROM    tblFLTNUMS t1
    JOIN    tblCUSTDETAILS t2
        ON t1.cust_id = t2.cust_id
    JOIN    tblCONTACTS t3
        ON t1.cust_id = t3.cust_id
    ORDER BY flt_dt, contact_dt, cust_name DESC
    ;   As you can see by the atttached example Joh Smith had a fault on the 01/01/2010 and contacted us on the 01/01, 01/02 and not on the 01/03 but I want the 01/03 to say 0.
    As this is just a one of report I can not rebuild the tables so a SQL based solution is required.
    I hope you can help.

    I'm not sure what you are really after but I gave it a shot:
    SQL> WITH tblCUSTDETAILS AS (
      2      SELECT  '11111' AS CUST_ID, 'John Smith' AS CUST_NAME FROM DUAL UNION ALL
      3      SELECT  '11112' AS CUST_ID, 'Andy Wilson' AS CUST_NAME FROM DUAL
      4  ), tblFLTNUMS AS (
      5      SELECT  '11111' AS CUST_ID, TO_DATE('JAN-10', 'MON-YY') AS FLT_DT FROM DUAL UNION ALL
      6      SELECT  '11112', TO_DATE('FEB-10', 'MON-YY') FROM DUAL UNION ALL
      7      SELECT  '11112', TO_DATE('APR-10', 'MON-YY') FROM DUAL
      8  ), tblCONTACTS AS (
      9      SELECT  '11111' AS CUST_ID, TO_DATE('JAN-10', 'MON-YY') AS CONTACT_DT, 5 AS CONTACT_VOL FROM DUAL UNION ALL
    10      SELECT  '11111', TO_DATE('FEB-10', 'MON-YY'), 3 FROM DUAL UNION ALL
    11      SELECT  '11112', TO_DATE('MAR-10', 'MON-YY'), 1 FROM DUAL UNION ALL
    12      SELECT  '11112', TO_DATE('MAY-10', 'MON-YY'), 2 FROM DUAL
    13  ), tblMonthParameters AS (
    14          SELECT  MIN(FLT_DT) AS startMonth
    15          ,       ADD_MONTHS(MAX(FLT_DT),2) AS endMonth
    16          FROM    tblFLTNUMS
    17  ), tblMONTHS AS (
    18          SELECT  ADD_MONTHS(startMonth,ROWNUM - 1) AS DT
    19          FROM    tblMonthParameters
    20          CONNECT BY LEVEL <= MONTHS_BETWEEN(endMonth,startMonth) + 1
    21  )
    22  SELECT  t1.cust_id,
    23          t2.cust_name,
    24          t1.flt_dt,
    25          t3.dt,
    26          NVL(t3.contact_vol,0)   AS CONTACT_VOL
    27  FROM    tblFLTNUMS t1
    28  JOIN    tblCUSTDETAILS t2
    29      ON t1.cust_id = t2.cust_id
    30  JOIN    (
    31                  SELECT  CUST_ID
    32                  ,       CONTACT_VOL
    33                  ,       DT
    34                  FROM    tblCONTACTS PARTITION BY (tblCONTACTS.CUST_ID)
    35                  RIGHT JOIN tblMONTHS  ON tblCONTACTS.CONTACT_DT = tblMONTHS.DT
    36          ) t3
    37      ON  t3.CUST_ID = T1.CUST_ID
    38      AND MONTHS_BETWEEN(t3.DT,t1.FLT_DT) BETWEEN 0 AND 2
    39  ORDER BY flt_dt, dt, cust_name DESC
    40  ;
    CUST_ CUST_NAME   FLT_DT              DT                           CONTACT_VOL
    11111 John Smith  01/01/2010 00:00:00 01/01/2010 00:00:00                    5
    11111 John Smith  01/01/2010 00:00:00 02/01/2010 00:00:00                    3
    11111 John Smith  01/01/2010 00:00:00 03/01/2010 00:00:00                    0
    11112 Andy Wilson 02/01/2010 00:00:00 02/01/2010 00:00:00                    0
    11112 Andy Wilson 02/01/2010 00:00:00 03/01/2010 00:00:00                    1
    11112 Andy Wilson 02/01/2010 00:00:00 04/01/2010 00:00:00                    0
    11112 Andy Wilson 04/01/2010 00:00:00 04/01/2010 00:00:00                    0
    11112 Andy Wilson 04/01/2010 00:00:00 05/01/2010 00:00:00                    2
    11112 Andy Wilson 04/01/2010 00:00:00 06/01/2010 00:00:00                    0
    9 rows selected.I added two more tables to your WITH clause. The tblMonthParameters calculates the minimum FLT_DT and maximum FLT_DT + 2 months based on your three month fault requirement. The tblMonths takes these input parameters and generates a dense month range.
    This dense month range is then outer joined using the PARTITION BY syntax to the tblCONTACTS table to generate the range of months for each customer. This result is then used as a subquery to the original main query that you had joining based on the customer and FLT_DT. Where the customer did not contact for a particular month I've placed a 0 in the CONTACT_VOL column.
    If this isn't correct please let me know. This solution depends on 10g so if you don't have it you may have to find another way to achieve this.
    HTH!

Maybe you are looking for

  • Shouldn't this work? dd command issues.

    I'm hoping to bring together a hodge podge of old parts lying about into a sweet smoking Arch machine. I've got everything I need, except what I thought would be the easiest part of the whole box... a usable hard disk. After finding two reasonably ne

  • How does JRE handle PKI certificates?

    I've got a bunch of Macs, all running OS X 10.10.2 and JRE 8u31  Most, no problems.  But I've got two on which Java complains about the certificates of at least one web site.  In the browser, the cert is just fine.  Trusted, etc.  Java doesn't think

  • Multiple channels switch scanning DMM

    Hi, I am using DMM (NI PXI  4071) and switch (NI TB 2627). I want to do the measurement by scanning one channel then start to measure, after that go to another channel and start to measure again (so called syncronous). But, I have problem in my code

  • Amail account wizard problems

    Abeg my blackberry torch 1 email account setup is not working..how can I fix it?

  • Help with recording 2 tracks at the same time

    Basically I recently purchased an Audio Interface (BEHRINGER XENYX Q802 USB) and I'm having trouble recording multiple tracks at the same time while using it. When I set up 2 MONO tracks in my DAW (one using input 1, the other using input 2) all that