Reg: Query using Decode

Hi,
Below mentioned query
select p.PRODUCTREF , BRANDID,
                    decode(fsr_rw_featureid,'CR0189',decode(languagecode,'fr',value ,decode(languagecode,'WW',value))) CR0189,
                    decode(fsr_rw_featureid,'CR0243',decode(languagecode,'fr',value ,decode(languagecode,'WW',value))) CR0243,
                    decode(fsr_rw_featureid,'CR0305',decode(languagecode,'fr',value ,decode(languagecode,'WW',value))) CR0305,
                    decode(fsr_rw_featureid,'CR0306',decode(languagecode,'fr',value ,decode(languagecode,'WW',value))) CR0306,
                    decode(fsr_rw_featureid,'CR0308',decode(languagecode,'fr',value ,decode(languagecode,'WW',value))) CR0308,
                    decode(fsr_rw_featureid,'CR0309',decode(languagecode,'fr',value ,decode(languagecode,'WW',value))) CR0309,
                    decode(fsr_rw_featureid,'CR0311',decode(languagecode,'fr',value ,decode(languagecode,'WW',value))) CR0311
from v_product p,
                    v_product_feature_value pfv,
                    TB14_featureid_sparc_rw fpr
where fpr.fsr_sparc_featureid = pfv.featureid
and pfv.productref= p.productref
and languagecode in ('fr')
                    --and languagecode in (?,?,?,?,?,?)
                    and fsr_rw_featureid in ('CR0189','CR0243','CR0305','CR0306','CR0308','CR0309','CR0311')                
               )nc_product,
now displayed output
product brand CR0189 CR0243 CR0305 CR0306 CR0308 CR0309 CR0311
101 B012 7
101 B012 5
101 B012 3
101 B012 1
101 B012 12
101 B012 17
101 B012 19
here need the output is
101 B012 7 5 3 1 12 17 19
How to frame the query . Kindly sugget me.
Regards,
Sudhakar P.

now displayed output
product brand CR0189 CR0243 CR0305 CR0306 CR0308 CR0309 CR0311
101 B012 7 Null Null Null Null Null Null
101 B012 Null 5 Null Null Null Null Null
101 B012 Null Null 3 Null Null Null Null
101 B012 Null Null Null 1 Null Null Null
101 B012 Null Null Null Null 12 Null Null
101 B012 Null Null Null Null Null 17 Null
101 B012 Null Null Null Null Null Null 19
here need the output is
101 B012 7 5 3 1 12 17 19
How to frame the query . Kindly sugget me.
Regards,
Sudhakar P.

Similar Messages

  • Basic query using DECODE not working as expected.

    Version:11.2.0.3
    Platform: RHEL 5.8
    I am trying to use DECODE function.
    In the below example, If the search encounters the string "Enterprise" , then the decode should
    return 'Enterprise' . But it doesn't seem to work.
    I thought some hidden character was causing the issue, so, I used TRIM. But no luck.
    SQL> create table t (banner varchar2(80));
    Table created.
    SQL> insert into t values ('Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production');
    1 row created.
    SQL> commit;
    Commit complete.
    SQL> select * from t;
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    SQL> select * from t where banner like '%Database%';
    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production
    -- Trying to use decode. If the search encounters the string "Enterprise" , then return 'Enterprise'
    -- Although the string "Enterprise" is present ,  decode doesn't seem to work.
    -- I tried using trim , upper . But no luck.
    SQL> select 'EDITION', decode(banner,'%Enterprise%','Enterprise','Standard') Edition from t where banner like '%Database%';
    'EDITIO EDITION
    EDITION Standard
    SQL> select 'EDITION', decode(trim(banner), '%Enterprise%','Enterprise','Standard') Edition from t where trim(banner) like '%Database%';
    'EDITIO EDITION
    EDITION Standard
    SQL> select 'EDITION', decode(upper(trim(banner)), '%ENTERPRISE%','Enterprise','Standard') Edition from t where upper(trim(banner)) like '%DATABASE%';
    'EDITIO EDITION
    EDITION Standard
    SQL>
    Just don't understand why decode can't see the string "Enterprise"
    BTW . Where is the preview button ?

    It (a portion string matching) ain't work in DECODE, for this CASE has a advantage of using over it.
    Like
    with t
    as
    (select 'Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - 64bit Production' banner from dual)
    select 'EDITION',
    case when banner like '%Enterprise%' then 'Enterprise' else 'Standard' end edition
    from t
    'EDITIO EDITION
    EDITION Enterprise

  • Sql query in decode

    Hi,
    I want to run query using decode given below:
    decode(
    (select count....from t1),0,(select count...from t2),1)
    MEans, if count of query from table t1 returns 0 then execute query of t2 table else return 1. If then else of query.. can i do this in decode ? if yes, how?
    thanks,
    JP

    CASE is relevant here:
    SQL> select case when (select name from nc_objects where rownum = 1) = 'CSM-AB-155FSH-2W' then 0
      2  else 1 end col1 from dual;
          COL1
             0Rgds.

  • Sqlserver query using Group by and Order by

    SUM(BILL_DETAIL.x_bill_quantity) as BILL_QUANTITY,
    MIN(BILL_DETAIL.x_billable_to) as BILLABLE_TO,
    MIN(BILL_DETAIL.x_billable_yn) as BILLABLE_YN,
    AVG(BILL_DETAIL.x_bill_rate) as BILL_RATE,
    MIN(BILL_DETAIL.x_cost_rate) as COST_RATE,
    MIN(BILL_DETAIL.x_cost_total) as COST_TYPE,
    LISTAGG(BILL_DETAIL.objid, ',') WITHIN GROUP(ORDER BY BILL_DETAIL.objid) as ID_LIST
    FROM table_x_gsa_bill_detail BILL_DETAIL
    WHERE (1=1)
    GROUP BY (DECODE(BILLABLE_YN, 1, 'Billable', 'Non-Billable') || ',' || BILLABLE_TO || ',' || DETAIL_CLASS || ',' || COST_TYPE || ',' || BILL_RATE)
    ORDER BY DECODE(BILLABLE_YN, 1, 'Billable', 'Non-Billable') || ',' || BILLABLE_TO || ',' || DETAIL_CLASS ||
    ) dt WHERE rn BETWEEN 0 AND 1
    Can any one pls help me using of Case Condition keyword instead of Decode in the above query ??? iam not able to convert above query for group by and order by..
    Actually i need to do group by the aggragate values which i got the values from the fields of BILLABLE_YN,BILLABLE_TO,DETAIL_CLASS, COST_TYPE, BILL_RATE.
    where as in oracle i can run above query using decode keyword where as in sqlserver iam not able to use BILLABLE_YN field alias of above query in group by .
    i tried like by using following way but it is wrong because here iam not using aggragate values of fields in group by funtion please help me in converting query in sqlserver. GROUP BY (case BILLABLE_YN when 1 then 'Billable' when 0 then 'Non-Billable' else
    'Non-Billable' End BILLABLE_YN + ',' + BILLABLE_TO + ',' + DETAIL_CLASS + ',' + COST_TYPE + ',' + BILL_RATE)
    Krishna

    CREATE TABLE DETAIL
    ([objid] int,[x_billable_to] varchar(19), [x_bill_quantity] int,
    [x_billable_yn] int, [x_bill_rate] int, [COST_TYPE] varchar(19) )
    INSERT INTO
    DETAIL
    ([objid], [x_billable_to], [x_bill_quantity], [x_billable_yn], [x_bill_rate],[COST_TYPE])
    VALUES
    (1, 'Customer', 3, 1, 20,'Parking'),
    (2, 'Customer', 1, 1, 25,'Toll'),
    (3, 'Customer', 2, 1, 20,'Parking') 
    Pls convert following query for executing query in sqlserver  ..for the column ID_List it should return data like 1,2,3
    SELECT * FROM (SELECT 1 rn,
            SUM(BILL_DETAIL.x_bill_quantity)      as BILL_QUANTITY,
            MIN(BILL_DETAIL.x_billable_to)        as BILLABLE_TO,
            MIN(BILL_DETAIL.x_billable_yn)        as BILLABLE_YN,
            AVG(BILL_DETAIL.x_bill_rate)          as BILL_RATE,
            LISTAGG(BILL_DETAIL.objid, ',') WITHIN GROUP(ORDER BY BILL_DETAIL.objid) as ID_LIST
         FROM   BILL_DETAIL
          WHERE (1=1)
     GROUP BY (DECODE(x_billable_yn, 1, 'Billable', 'Non-Billable') + ',' + x_billable_to  +  ',' + COST_TYPE + ',' + x_bill_rate)
          ORDER BY DECODE(x_billable_yn, 1, 'Billable', 'Non-Billable') + ',' + x_billable_to  +  ',' + COST_TYPE + ',' + x_bill_rate
           )dt 
    WHERE rn BETWEEN 0 AND 1
    Krishna
    sounds like this
    SELECT *
    FROM
    SELECT 1 rn,
    SUM(BILL_DETAIL.x_bill_quantity) as BILL_QUANTITY,
    MIN(BILL_DETAIL.x_billable_to) as BILLABLE_TO,
    MIN(BILL_DETAIL.x_billable_yn) as BILLABLE_YN,
    AVG(BILL_DETAIL.x_bill_rate) as BILL_RATE,
    LEFT(bd1.ID_LIST,LEN(bd1.ID_LIST)-1) AS ID_Listing
    FROM BILL_DETAIL bd
    CROSS APPLY (
    SELECT BILL_DETAIL.objid + ',' AS [text()]
    FROM BILL_DETAIL
    WHERE objid = bd.objid
    FOR XML PATH('')
    )bd1(ID_LIST)
    WHERE (1=1)
    GROUP BY (CASE WHEN x_billable_yn = 1 THEN 'Billable' ELSE 'Non-Billable'END + ',' + x_billable_to + ',' + COST_TYPE + ',' + x_bill_rate),
    LEFT(bd1.ID_LIST,LEN(bd1.ID_LIST)-1)
    ORDER BY (CASE WHEN x_billable_yn = 1 THEN 'Billable' ELSE 'Non-Billable'END + ',' + x_billable_to + ',' + COST_TYPE + ',' + x_bill_rate),
    LEFT(bd1.ID_LIST,LEN(bd1.ID_LIST)-1)
    )dt
    WHERE rn BETWEEN 0 AND 1
    Please Mark This As Answer if it solved your issue
    Please Vote This As Helpful if it helps to solve your issue
    Visakh
    My Wiki User Page
    My MSDN Page
    My Personal Blog
    My Facebook Page

  • How to use index, when query has decode/case

    Hi,
    I have the following query
    i have a index on party_id,party_type_Code in the zx_party_tax_profile table But this index is not used as Iam using a decode on the columns of the zx_party_tax_profile table,
    Is there any way i can rewrite the query so that it uses index
    sELECT /*+ INDEX(ZX_PARTY_TAX_PROFILE_U2) */ party_tax_profile_id FROM (SELECT
    ThirdPartyTaxProfileEO.SUPPLIER_FLAG,
    ThirdPartyTaxProfileEO.CUSTOMER_FLAG,
    ThirdPartyTaxProfileEO.SITE_FLAG,
    ThirdPartyTaxProfileEO.PARTY_TAX_PROFILE_ID,
    ThirdPartyTaxProfileEO.PARTY_ID,
    ThirdPartyTaxProfileEO.REP_REGISTRATION_NUMBER,
    ThirdPartyTaxProfileEO.OBJECT_VERSION_NUMBER,
    ThirdPartyTaxProfileEO.REGISTRATION_TYPE_CODE,
    ThirdPartyTaxProfileEO.COUNTRY_CODE,
    ThirdPartyTaxProfileEO.MERGED_TO_PTP_ID,
    ThirdPartyTaxProfileEO.MERGED_STATUS_CODE,
    ThirdPartyTaxProfileEO.PROGRAM_APP_NAME,
    ThirdPartyTaxProfileEO.PROGRAM_NAME,
    PartyPEO.PARTY_NAME,
    PartyPEO.PARTY_ID AS PARTY_ID1,
    PartyPEO.PARTY_NUMBER,
    decode(ThirdPartyTaxProfileEO.CUSTOMER_FLAG,
    'Y',decode(ThirdPartyTaxProfileEO.SUPPLIER_FLAG,
    'Y', 'SC',
    'C'),
    decode(ThirdPartyTaxProfileEO.SUPPLIER_FLAG,
    'Y', 'S',
    NULL)
    ) AS PARTY_USAGE,
    ThirdPartyTaxProfileEO.REP_REGISTRATION_NUMBER AS TAX_REG_NUMBER,
    LkupPartyUsage.MEANING AS PARTY_USAGE_DESC,
    PartyPEO.PARTY_NAME AS PARTY_FULL_NAME,
    PartyPEO.ADDRESS1||','||
    PartyPEO.ADDRESS2||','||
    PartyPEO.ADDRESS3||','||
    PartyPEO.CITY||','||
    PartyPEO.postal_code||','||
    PartyPEO.COUNTRY AS ADDRESS,
    PartyPEO.COUNTRY AS COUNTRY_CODE_TCA,
    TerritoryPEO.TERRITORY_SHORT_NAME AS COUNTRY_NAME,
    PartyPEO.JGZZ_FISCAL_CODE AS TAX_PAYER_ID,
    PartyPEO.DUNS_NUMBER_C AS DUNS_NUMBER,
    PartyPEO.Party_Number as Party_Num_Calc,
    null as REGISTRATION_TYPE_NAME,
    null as ROUNDING_LEVEL_NAME,
    null as ROUNDING_RULE_NAME,
    null as COUNTRY_NAME_PTP,
    'ZX_PARTY_TAX_PROFILE' as TAX_REPORTING_ENTITY_CODE
    FROM ZX_PARTY_TAX_PROFILE ThirdPartyTaxProfileEO,
    HZ_PARTIES PartyPEO,
    FND_LOOKUP_VALUES_VL LkupPartyUsage,
    FND_TERRITORIES_VL TerritoryPEO
    WHERE ThirdPartyTaxProfileEO.PARTY_ID = PartyPEO.PARTY_ID AND
    LkupPartyUsage.LOOKUP_CODE = decode(ThirdPartyTaxProfileEO.CUSTOMER_FLAG,
    'Y',decode(ThirdPartyTaxProfileEO.SUPPLIER_FLAG,
    'Y', 'SC',
    'C'),
    decode(ThirdPartyTaxProfileEO.SUPPLIER_FLAG,
    'Y', 'S',
    NULL)
    ) AND
    PartyPEO.COUNTRY = TerritoryPEO.Territory_Code (+) AND
    LkupPartyUsage.LOOKUP_TYPE = 'ZX_TP_PARTY_USAGE'
    ORDER BY UPPER(PARTY_FULL_NAME)) QRSLT WHERE UPPER(PARTY_NAME) IS NOT
    NULL
    Any help will be appreciated

    You can rewrite your where clause to not use decode or case statements e.g. this:
      AND LkupPartyUsage.LOOKUP_CODE = DECODE( ThirdPartyTaxProfileEO.CUSTOMER_FLAG
                                , 'Y', DECODE( ThirdPartyTaxProfileEO.SUPPLIER_FLAG, 'Y', 'SC', 'C' )
                                     , DECODE( ThirdPartyTaxProfileEO.SUPPLIER_FLAG, 'Y', 'S', NULL ) )
                                     )can be rewritten to this:
    and (
          ( ThirdPartyTaxProfileEO.CUSTOMER_FLAG = 'Y'  AND
              ((ThirdPartyTaxProfileEO.SUPPLIER_FLAG = 'Y' AND LkupPartyUsage.LOOKUP_CODE = 'SC') or
                ThirdPartyTaxProfileEO.SUPPLIER_FLAG != 'Y' AND LkupPartyUsage.LOOKUP_CODE = 'C')) or
          ( ThirdPartyTaxProfileEO.CUSTOMER_FLAG != 'Y'  AND
              ((ThirdPartyTaxProfileEO.SUPPLIER_FLAG = 'Y' AND LkupPartyUsage.LOOKUP_CODE = 'S') or
                ThirdPartyTaxProfileEO.SUPPLIER_FLAG != 'Y' AND LkupPartyUsage.LOOKUP_CODE is null))
        )It's not as sussinct, but it avoids the use of functions that could be preventing the optimiser from using an index.

  • Query to find out sum by using decode or case

    Hi, I have data like below and required an output as given below, could you please help me to get the same by using decode / case .....Thanks for your help
    INSNAME INSID STATUS
    AAA 1000 Scheduled
    AAA 1000 Processing
    BBB 1001 Inspector
    BBB 1001 Scheduled
    BBB 1001 Processing
    BBB 1001 Inspector
    CCC 1002 Scheduled
    CCC 1002 Processing
    CCC 1002 Inspector
    CCC 1002 Scheduled
    CCC 1002 Processing
    CCC 1002 Inspector
    Required Output...
    INSNAME INSID sum_of_scheduled sum_of_Processing sum_of_Inspector
    AAA 1000 1 1 0
    BBB 1001 1 1 2
    CCC 1002 2 2 2

    And if you want it with CASE statement:
    WITH test_table AS
       SELECT 'AAA' insname, 1000 insid, 'Scheduled'   status FROM DUAL UNION ALL
       SELECT 'AAA' insname, 1000 insid, 'Processing'  status FROM DUAL UNION ALL
       SELECT 'BBB' insname, 1001 insid, 'Inspector'   status FROM DUAL UNION ALL
       SELECT 'BBB' insname, 1001 insid, 'Scheduled'   status FROM DUAL UNION ALL
       SELECT 'BBB' insname, 1001 insid, 'Processing'  status FROM DUAL UNION ALL
       SELECT 'BBB' insname, 1001 insid, 'Inspector'   status FROM DUAL UNION ALL
       SELECT 'CCC' insname, 1002 insid, 'Scheduled'   status FROM DUAL UNION ALL
       SELECT 'CCC' insname, 1002 insid, 'Processing'  status FROM DUAL UNION ALL
       SELECT 'CCC' insname, 1002 insid, 'Inspector'   status FROM DUAL UNION ALL
       SELECT 'CCC' insname, 1002 insid, 'Scheduled'   status FROM DUAL UNION ALL
       SELECT 'CCC' insname, 1002 insid, 'Processing'  status FROM DUAL UNION ALL
       SELECT 'CCC' insname, 1002 insid, 'Inspector'   status FROM DUAL
    SELECT insname
          ,insid
          ,SUM(CASE WHEN status = 'Scheduled'
                    THEN 1
                    ELSE 0
                END
              ) sum_of_scheduled
          ,SUM(CASE WHEN status = 'Processing'
                    THEN 1
                    ELSE 0
                END
              ) sum_of_processing
          ,SUM(CASE WHEN status = 'Inspector'
                    THEN 1
                    ELSE 0
                END
              ) sum_of_inspector         
      FROM test_table
    GROUP BY insname
            ,insid;
    Regards
    Arun

  • How to use decode function in oracle apex 3.2.1

    Hello Friends,
    how to use decode
    var_decode := 'decode'||'('|| var1 ||','|| -800000000000000||','||'.A'||','||
    appreciate your help.
    regards/kumar
    Edited by: kumar73 on Apr 23, 2010 12:25 PM
    Edited by: kumar73 on Apr 23, 2010 12:27 PM

    Hey just on this particular point, there's a handy PL/SQL method for escaping quotation characters which may reduce the complexity of the string.
    For example, if I had a string:
    I can't understand why quoting my 'quote' characters never seems to "work"!and I wanted to pass that into a variable, I could do this:
    vc_foo:= 'I can''t understand why my ''quote'' characters never seems to "work"!';or I could use the q function, whereby you enclose your string within a quote delimiter of your choice, like so:
    vc_foo:= q'^I can't understand why quoting my 'quote' characters never seems to "work"!^';
    note: I used the caret (^) character by convention but any valid character will do
    ...all of which leaves your original string more or less unadulterated.
    I find this particularly useful for generating dynamic SQL and dynamic PL/SQL, as it leave the query looking a tad more readable, although if you are chaining together multiple strings with double-pipes, it can make it a little muddier. I find it particularly useful if I'm going to deal with string data from, for example, a field with Irish-derived surnames such as "O'Reilly"...
    Give it a go!

  • How to use decode to calculate sum for different date range

    I'm stuck with decode() function:
    I have a table like this:
    (project_id, approve_date, value, builder_code)
    I want to write a SQL query to get sum of values for different month of the approve_date, and group by builder_code)
    The result is like this:
    builder_code Sum(value)_Sep-03 Sum(value)_Oct-03 Sum(value)_Nov03
    1001 1,299 1,322 990
    1002 3,332 1,222 333
    I tried to use decode for this question but could not get the answer.
    Thanks a lot

    I don't think you need a DECODE() here. I'd do something like this-
    create table builder (
        project_id number,
        approve_date date,
        value        number,
        builder_code number
    insert into builder values( 1, to_date('09-01-2003', 'MM-DD-YYYY'), 100, 990 )
    insert into builder values( 2, to_date('09-03-2003', 'MM-DD-YYYY'), 150, 990 )
    insert into builder values( 3, to_date('09-05-2003', 'MM-DD-YYYY'), 250, 990 )
    insert into builder values( 3, to_date('09-05-2003', 'MM-DD-YYYY'), 250, 333)
    SELECT sept.builder_code, sept.sept_sum, oct.oct_sum
    FROM (SELECT builder_code, sum(value) sept_sum
            FROM builder
           WHERE approve_date >= to_date('09-01-2003','MM-DD-YYYY')
             AND approve_date < to_date('10-01-2003','MM-DD-YYYY')
           GROUP BY builder_code) sept,
         (SELECT builder_code, sum(value) oct_sum
            FROM builder
           WHERE approve_date >= to_date('10-01-2003','MM-DD-YYYY')
             AND approve_date < to_date('11-01-2003','MM-DD-YYYY')
           GROUP BY builder_code) oct
    WHERE oct.builder_code(+) = sept.builder_code
    BUILDER_CODE   SEPT_SUM    OCT_SUM
             333        250
             990        500Justin
    Distributed Database Consulting, Inc.
    www.ddbcinc.com/askDDBC

  • Pl/sql using DECODE

    Hello,
    i have question regarding PL/SQL using DECODE when i use following qurey in SQL plus it is working fine but when i try to run in tode it only display value of g.
    everything else is blank........
    so can u plz assist me on that .....
    thanks in advance!!!!!!!!!!
    SELECT
    b.g,b.s,
    COUNT(DECODE(a.u,'R',a.rep)) AS R,
    COUNT(DECODE(a.u,'u',a.rep)) AS U,
    COUNT(DECODE(a.u,'C',a.rep))AS C,
    COUNT(DECODE(a.u,'I',a.rep)) AS I,
    COUNT(DECODE(a.u,NULL,a.rep)) AS B
    FROM AREA a, data b
    WHERE a.rep = '454637'
    AND a.rep = b.emp
    GROUP BY b.g,b.s

    Very strange.
    Find out if there are alterations to your SQL*PLUS envirionment. Warren mentioned user/database wierdness; the ALTER SCHEMA and other commands can affect privilges and what objects you can see. Sometimes these commands are buried in LOGIN.SQL and GLOGIN.SQL files (for SQL*PLUS), and more hard to find they can call files buried on a network somewhere.
    Try the query without the DECODE() and see what's in the table without trying to modify the values in both envirionments.

  • Please help to re-write this query using exists or with

    Hi please help to re-write this query using exists or with, i need to write same code for 45 day , 90 days and so on but sub query condition is same for all
    SELECT SUM (DECODE (t_one_mon_c_paid_us, 0, 0, 1)) t_two_y_m_mul_ca_
    FROM (SELECT SUM (one_mon_c_paid_us) t_one_mon_c_paid_us
    FROM (
    SELECT a.individual_id individual_id,
    CASE
    WHEN NVL
    (b.ship_dt,
    TO_DATE ('05-MAY-1955')
    ) >= SYSDATE - 45
    AND a.country_cd = 'US'
    AND b.individual_id in (
    SELECT UNIQUE c.individual_id
    FROM order c
    WHERE c.prod_cd = 'A'
    AND NVL (c.last_payment_dt,
    TO_DATE ('05-MAY-1955')
    ) >= SYSDATE - 745)
    THEN 1
    ELSE 0
    END AS one_mon_c_paid_us
    FROM items b, addr a, product d
    WHERE b.prod_id = d.prod_id
    AND d.affinity_1_cd = 'ADH'
    AND b.individual_id = a.individual_id)
    GROUP BY individual_id)
    Edited by: user4522368 on Aug 23, 2010 9:11 AM

    Please try and place \ before and after you code \Could you not remove the inline column select with the following?
    SELECT a.individual_id individual_id
         ,CASE
            when b.Ship_dt is null then
              3
            WHEN b.ship_dt >= SYSDATE - 90
              3
            WHEN b.ship_dt >= SYSDATE - 45
              2
            WHEN b.ship_dt >= SYSDATE - 30
              1
          END AS one_mon_c_paid_us
    FROM  items           b
         ,addr            a
         ,product         d
         ,order           o
    WHERE b.prod_id       = d.prod_id
    AND   d.affinity_1_cd = 'ADH'
    AND   b.individual_id = a.individual_id
    AND   b.Individual_ID = o.Individual_ID
    and   o.Prod_CD       = 'A'             
    and   NVL (o.last_payment_dt,TO_DATE ('05-MAY-1955') ) >= SYSDATE - 745
    and   a.Country_CD    = 'US'

  • How to use decode function

    Hello Friends,
    I have a query that has different columns and I am not sure what the data type of each column is ...
    I want to use decode function which displays the following if the value of the column is like this ..
    if the value of column is -714E ie -700000000000000 then display as .A
    if the value of column is -814E ie -800000000000000 then display as .B
    NOTE ; don't know which column is having the value - and i don't know the data type of the column is ..
    got to use the decode function for all the columns selected ..
    I want to use decode function pls let me know how to write for this kind of requirement.
    appreciate your help in this rgds.
    thanks/kumar

    Dear Sir / Madam,
    Thanks for your understanding.
    Right now I am facing a unique problem.
    I am using decode function in a select statement. The columns are dynamic some columns are of type number and some are varchar datatypes. I want to apply decode function for every column irrespective of datatype.
    What i am finding difficult is if the column is a number datatype , the decode funciton is working good but if the column datatype is varchar or char datatype then i am getting ..
    here's the decode function..
    decode (CHAI.EVNDRIVE,
    -800000000000000,'.A',
    -700000000000000, '.B',
    -600000000000000 ,'.C',
    -500000000000000 , '.D',
    -400000000000000 , '.E',
    -300000000000000 , '.F',
    -200000000000000, '.G',
    -100000000000000 , '.H',
    -1000000000, '.R' ,CHAI.EVNDRIVE ) EVNDRIVE
    report error:
    ORA-01722: invalid number
    pls let me know how to over come this kind of scenario.
    is their a way to find whether the column datatype is number or char , so that i can check the column datatype before the decode funciton is applied ..
    thanks ..
    kumar

  • How to use decode concept in htp.p?

    Hi All,
    How to use decode function in htp.p syntax?
    Thanks,
    Anoo..

    Hi,
    Could you please give more details on what you like to achieve? Decode function works only in sql query.
    You can first do sql query, and then do htp.p.
    Or you can use PL/SQL IF or CASE statements.
    You can also create custom decode function if you need.
    Regards,
    Oleg

  • How to Use Decode for manipulating time

    How can i use Decode function to manipulate time...
    Example
    suppose ive employee and his time in...i want to display status field by using decode,which reflects if that employee came after 09:15:00 the status='L' else this will print 'P'
    i tried this
    SELECT pin_code,DECODE( to_char(ACCESS_TIME,'HH24:MI:SS'>'09:15:00','l','P'))STATUS
    FROM ATTENDANCE_REG
    this query hasn't work...
    waiting for reply
    Regards
    Danish Hayder

    SQL> select case when to_number(to_char(sysdate,'sssss')) > 33300 then 'L'
      2              else 'P' end status
      3  from dual;
    S
    L
    1 row selected.                                                                                                                                                                                                                                                                                                                                           

  • Insert while using Decode Statement

    Hi,
    I have a unique problem(I think so). Is it possibe to insert into a table while selecting from another table using DECODE function. I am giving the select statement below. When I run this statement it says that missing expression. I could not find out the mistake. Is this query right or any changes to be made. Moreover I would like to know whether it is the right way of doing.
    The SQL Statement is as follows.
    SQL> select decode(EV,'E',(INSERT INTO assets1 VALUES
    (31,NULL,NULL))) from assets;
    Thanking in advance for timely help.
    Guru Prasad.

    Hi,
    U Cannot do that ... B'cos u cannot have Insert Inside a Select.
    What you can do is... Right a Small Pl/SQL Block which will do that for you.
    Regards,
    Ganesh R

  • Problem using Decode/Case

    I have one table which stores candidates' response. The structure is like this
    (Seatno, Questionnumber, Answer).
    And I have another table Master as (Questionnumber, Answer)
    Now I want to calculate marks by comparing Candidate's response with Master.
    I tried to use decode and case. But was not successful.
    My query with decode was ...
    select c1.candidatesrno, sum(decode(c1.answer,(c1.answer=m1.answer),1,0))
    from candidate c1,master q1
    where c1.question=m1.question
    group by c1.candidatesrno
    And query with CASE was...
    select c1.candidatesrno,
    case when (c1.answer=m1.answer) then 1 else 0
    end resultset
    from candidate c1,master m1
    where c1.questionnumber=m1.questionnumber
    group by c1.candidatesrno
    Can anybody help ?

    I want to compare candidate's response with master
    table.
    Now for each question of Candidate, if its answer
    matches with answer in Master table I have to give 1
    marks...if it does not match I have to give 0
    marks...like this there are two-three conditions...
    Something like this ?
    test@ORA10G>
    test@ORA10G> with master as (
      2    select 'Q1' as question_num, 'A1' as answer_num from dual union all
      3    select 'Q2', 'A2' from dual union all
      4    select 'Q3', 'A3' from dual),
      5  candidate_response as (
      6    select 'S1' as seat_num, 'Q1' as question_num, 'A1' as answer_num from dual union all
      7    select 'S1', 'Q2', 'A2' from dual union all
      8    select 'S1', 'Q3', 'A3' from dual union all
      9    select 'S2', 'Q1', 'A5' from dual union all
    10    select 'S2', 'Q2', 'A6' from dual union all
    11    select 'S2', 'Q3', 'A3' from dual)
    12  --
    13  select
    14    cr.seat_num,
    15    cr.question_num,
    16    cr.answer_num,
    17    case when m.question_num is null and m.answer_num is null then '0 point'
    18         else '1 point'
    19    end as points
    20  from candidate_response cr, master m
    21  where cr.question_num = m.question_num(+)
    22  and cr.answer_num = m.answer_num(+)
    23  order by cr.seat_num, cr.question_num, cr.answer_num;
    SE QU AN POINTS
    S1 Q1 A1 1 point
    S1 Q2 A2 1 point
    S1 Q3 A3 1 point
    S2 Q1 A5 0 point
    S2 Q2 A6 0 point
    S2 Q3 A3 1 point
    6 rows selected.
    test@ORA10G>
    test@ORA10G> with master as (
      2    select 'Q1' as question_num, 'A1' as answer_num from dual union all
      3    select 'Q2', 'A2' from dual union all
      4    select 'Q3', 'A3' from dual),
      5  candidate_response as (
      6    select 'S1' as seat_num, 'Q1' as question_num, 'A1' as answer_num from dual union all
      7    select 'S1', 'Q2', 'A2' from dual union all
      8    select 'S1', 'Q3', 'A3' from dual union all
      9    select 'S2', 'Q1', 'A5' from dual union all
    10    select 'S2', 'Q2', 'A6' from dual union all
    11    select 'S2', 'Q3', 'A3' from dual)
    12  --
    13  select cr.seat_num, count(*) as score
    14  from candidate_response cr, master m
    15  where cr.question_num = m.question_num
    16  and cr.answer_num = m.answer_num
    17  group by cr.seat_num
    18  order by cr.seat_num;
    SE      SCORE
    S1          3
    S2          1
    test@ORA10G>
    test@ORA10G>pratz

Maybe you are looking for

  • Need my custom webauth page displayed with HTTP instead of HTTPS

    I have a custom webauth page installed that I am using with web passthrough authentication on my WLC2006 in order to put up a acceptable use policy page. The WLC uses HTTPS to display this which causes a security certificate warning to appear if I go

  • Mighty Mouse buttons 3 & 4 not working

    I am using the Mighty Mouse with a G4 PowerBook and the latest version of Tiger. At first the mouse worked fine. But a few days ago buttons 3 and 4 simply stopped working. I press them and nothing happens. I checked the mouse preference pane and it w

  • Creative Suite 3 Premium on Windows 8

    Does Creative Suite 3 Premium (CS3) run on Windows 8? Thanks!

  • Help: Custom Encoder + Netbeans 5.5.1 enterp. pack

    Help me, please: All points are finished in the Installation Guide for installing CustomEncoder component (link for guide - http://www.glassfishwiki.org/jbiwiki/Wiki.jsp?page=EncoderInstallation chapter "Installation Process for NetBeans IDE 5.5.1")

  • WRVS4400N DHCP problems

    Hello, I have a new router (obvious) but it seems to have problems with DHCP and also problems when using N function, especially on the 40 MHz band. First I thought the wireless NIC would be the problem but when I used another wireless NIC from a thi