Nested decode statement

Hi i was trying to get the below information.
I wanted to know is it possible to use nested decode function. also is it possible to use a condition in a decoded function.
how could i frame the below mentioned information into a nested decode statement.
IF LSGD = '00000000' then TC = "NS"
IF LSGD <> '00000000' and RP = 0 and RC =0 OR RU=0 then TC ="NU"
IF LSGD <> '00000000' and RP = 0 and RC >0 then TC="RR"
If RU > 1 and INT=0, then TC="TT"
If PERC is >=66% then TC="RR"
If PERC is < 66% then TC="TT"
thanks for your help

Hi Guido,
This is the case statement i have constructed. would appriciate if you could assist further to make it more accurate.
select
case when LSGD = '00000000' then 'NS'
when LSGD <> '00000000' then
case when RP=0 then case when RC=0 then 'NU' else case when RC >0 then 'RR' else 'TT' end end
else
case when RU=1 then 'NU' when RU>1 and INT=0 then 'TT' else 'RR' end
end
when PERC >=0.66 then 'RR'
when PERC < 0.66 then 'TT'
end TC
from my table
Thanks in advance

Similar Messages

  • Help with Nesting DECODE statements

    Hello. I'm trying to write a sql script to generate data report for payments. I need to incorporate specific conditions to SUPPRESS BLANK ADDRESS field lines. I am pulling Address_Line1, Address_Line2, Address_Line3, plus CITY, STATE, ZIP as Address_Line4. If any fields are blank, I need to suppress the blank line and move the other lines up.
    Here are my IF, THEN, ELSE conditions. There are 9 possible scenarios that I have identified. Can you please help me write this in SQL with the DECODE function?
    IF CITY||STATE||ZIP IS NULL               
    THEN AD1='12115 Rainbow Road', AD2='Hartford Heights, MO 60226'               
    ELSE               
         IF ADDRESS_LINE1 IS NULL          
              IF ADDRESS_LINE2 IS NULL     
                   IF ADDRESS_LINE3 IS NULL
                   THEN USE HOME ADDRESS
                   ELSE vAD1=ADDRESS_LINE3, vAD2=CITY||STATE||ZIP
                   ENDIF
              ELSE     
                   IF ADDRESS_LINE3 IS NULL
                   THEN vAD1=ADDRESS_LINE2, vAD2 = CITY||STATE||ZIP
                   ELSE vAD1=ADDRESS_LINE2, vAD2=ADDRESS_LINE3, vAD3=CITY||STATE||ZIP
                   ENDIF
              ENDIF     
         ELSE          
              IF ADDRESS_LINE2 IS NULL     
                   IF ADDRESS_LINE3 IS NULL
                   THEN vAD1=ADDRESS_LINE1, vAD2=CITY||STATE||ZIP
                   ELSE vAD1=ADDRESS_LINE1, vAD2=ADDRESS_LINE3, vAD3=CITY||STATE||ZIP
                   ENDIF
              ELSE     
                   IF ADDRESS_LINE3 IS NULL
                   THEN vAD1=ADDRESS_LINE1, vAD2=ADDRESS_LINE2, vAD3=CITY||STATE||ZIP
                   ELSE vAD1=ADDRESS_LINE1, vAD2=ADDRESS_LINE2, vAD3=ADDRESS_LINE3, vAD4=CITY||STATE||ZIP
                   ENDIF
              ENDIF     
         ENDIF          
    ENDIF               
    This what I've got so far...
    DECLARE
      vADR1
      vADR2
      vADR3
      vADR4
    BEGIN
    SELECT
    DECODE(
    END;
    /

    Hi,
    Here is the code along with some sample data. I substitute the "+" symbol for "/" becuase some addresses where using "c/o" in the address line.
    The address fields are null, as shown by the query below (ref query results below):
    SQL> select address_line1
      2  from po.po_vendor_sites_all
      3  where address_line1='3457 SOLUTIONS CENTER'
      4  and address_line2 is null;
    ADDRESS_LINE1
    3457 SOLUTIONS CENTERHere is the script:
    WITH got_delimited_list AS
    SELECT address_line1 || ' +' ||
    address_line2 || ' +' ||
    address_line3 || ' +' ||
    city ||', ' || state ||'  ' || zip AS delimited_list
    FROM po.po_vendor_sites_all
    SELECT REGEXP_SUBSTR (delimited_list, '[^+]+', 1, 1) AS vad1
    , REGEXP_SUBSTR (delimited_list, '[^+]+', 1, 2) AS vad2
    , REGEXP_SUBSTR (delimited_list, '[^+]+', 1, 3) AS vad3
    , REGEXP_SUBSTR (delimited_list, '[^+]+', 1, 4) AS vad4
    FROM got_delimited_list;Sample of the data records returned:
    VAD1
    VAD2
    VAD3
    VAD4
    3457 SOLUTIONS CENTER
    CHICAGO, IL  60677-3004
    VAD1
    VAD2
    VAD3
    VAD4
    5172 EAGLE WAY
    CHICAGO, IL  60678-1517
    VAD1
    VAD2
    VAD3
    VAD4
    RETAILERS' OCCUPATION TAX
    SPRINGFIELD, IL  62796-0001
    VAD1
    VAD2
    VAD3
    VAD4
    DEPT. NUMBER 478150
    P.O. BOX 790100
    ST LOUIS, MO  63179-9933
    VAD1
    VAD2
    VAD3
    VAD4
    P.O. BOX 62251
    BALTIMORE, MD  21264-2251
    VAD1
    VAD2
    VAD3
    VAD4
    P.O. BOX 660481
    DALLAS, TX  75266-0481
    VAD1
    VAD2
    VAD3
    VAD4
    3525 PIEDMONT RD.
    BUILDING FIVE
    SUITE 300
    ATLANTA, GA  30305

  • Nested Decode

    Hi All-
    I have a requirement where i need to convert a case statement into a nested decode statement here is the scenario
    CASE WHEN CD_FAM_01 = 'Y' THEN 'N'
    WHEN CD_FAM_02 = 'Y' THEN 'Y'
    WHEN CD_FAM_03 = 'Y' THEN 'Y'
    WHEN CD_FAM_04 = 'Y' THEN 'Y'
    WHEN CD_FAM_05 = 'Y' THEN 'Y'
    WHEN CD_FAM_01 IS NULL AND CD_FAM_02 IS NULL AND CD_FAM_03 IS NULL AND CD_FAM_04 IS NULL AND CD_FAM_05 IS NULL THEN 'N'
    WHEN CD_FAM_01 = 'N' AND CD_FAM_02 = 'N' AND CD_FAM_03 = 'N' AND CD_FAM_04 = 'N' AND CD_FAM_05 = 'N'THEN 'N' END
    I am facing a torrid time in converting this statement can you help me here

    SQL> create table ca_test (cd_fam_01 VARCHAR2(1),cd_fam_02 VARCHAR2(1),cd_fam_03 VARCHAR2(1),cd_fam_04 VARCHAR2(1),cd_fam_05 VARCHAR2(1));
    Table created.
    Elapsed: 00:00:00.02
    SQL>
    SQL> insert into ca_test VALUES ('Y','Y','Y','Y','Y');
    1 row created.
    Elapsed: 00:00:00.02
    SQL> insert into ca_test VALUES ('N','Y','Y','Y','Y');
    1 row created.
    Elapsed: 00:00:00.02
    SQL> insert into ca_test VALUES ('N','N','Y','Y','Y');
    1 row created.
    Elapsed: 00:00:00.02
    SQL> insert into ca_test VALUES ('N','N','N','Y','Y');
    1 row created.
    Elapsed: 00:00:00.02
    SQL> insert into ca_test VALUES ('N','N','N','N','Y');
    1 row created.
    Elapsed: 00:00:00.01
    SQL> insert into ca_test VALUES ('N','N','N','N','N');
    1 row created.
    Elapsed: 00:00:00.01
    SQL> insert into ca_test VALUES (null,null,null,null,null);
    1 row created.
    Elapsed: 00:00:00.00
    SQL> insert into ca_test VALUES ('N','N','N',null,null);
    1 row created.
    Elapsed: 00:00:00.00
    SQL>
    SQL> SELECT
      2    cd_fam_01
      3   ,cd_fam_02
      4   ,cd_fam_03
      5   ,cd_fam_04
      6   ,cd_fam_05
      7   ,DECODE
      8      (CD_FAM_01,'Y','N'
      9                    ,DECODE
    10                      (CD_FAM_02,'Y','Y'
    11                                    ,DECODE
    12                                        (CD_FAM_03,'Y','Y'
    13                                                      ,DECODE
    14                                                          (CD_FAM_04,'Y','Y'
    15                                                                        ,DECODE
    16                                                                           (CD_FAM_05,'Y','Y'
    17                                                                                         ,DECODE
    18                                                                                            (COALESCE
    19                                                                                                 (CD_FAM_01
    20                                                                                                 ,CD_FAM_02
    21                                                                                                 ,CD_FAM_03
    22                                                                                                 ,CD_FAM_04
    23                                                                                                 ,CD_FAM_05),NULL,'N'
    24                                                                                                                 ,DECODE
    25                                                                                                                    (GREATEST(CD_FAM_01
    26                                                                                                                             ,CD_FAM_02
    27                                                                                                                             ,CD_FAM_03
    28                                                                                                                             ,CD_FAM_04
    29                                                                                                                             ,CD_FAM_05),LEAST(CD_FAM_01
    30                                                                                                                                              ,CD_FAM_02
    31                                                                                                                                              ,CD_FAM_03
    32                                                                                                                                              ,CD_FAM_04
    33                                                                                                                                              ,CD_FAM_05),DECODE(GREATEST
    34                                                                                                                                                                   (CD_FAM_01
    35                                                                                                                                                                   ,CD_FAM_02
    36                                                                                                                                                                   ,CD_FAM_03
    37                                                                                                                                                                   ,CD_FAM_04
    38                                                                                                                                                                   ,CD_FAM_05),'N','N'))))))))
    39    FROM ca_test
    40   /
    C C C C C D
    Y Y Y Y Y N
    N Y Y Y Y Y
    N N Y Y Y Y
    N N N Y Y Y
    N N N N Y Y
    N N N N N N
              N
    N N N
    8 rows selected.
    Elapsed: 00:00:00.02Does this look alright? By the way, why are you doing this? The case statement is surely preferable.

  • Help! format of decode statements with between or signs ?

    Looking for an example of a decode statement with either a between/and or < > signs in the comparison field.
    I have tried several variations, but none seem to work. Any help would be appreciated.
    Here's a sample that doesn't work.
    Select course_no, section_no, capacity, decode(capacity, (capacity < 12), Less than 12, (capacity between 13 and 15), 13-15, More than 15) from section;
    Thanks in advance

    Hi,
    There is a limitation to the Case function, as it cannot be used in the PL/SQL (atleast upto Oracle 8i). Therefore, the only option left is Decode.
    If you have to compare the values like capacity < 12 then display Less than 12. You can write it using combination of other functions.
    For e.g. follow the steps below:-
    1)If you deduct 12 from capacity : (capacity-12) [it will give result as +ve, 0 or -ve.]
    2)If you have to narrow down the values to above three options, use function sign:
    SIGN(capacity-12) [will result into +1, 0 or -1]
    3)Then compare the values using Decode:
    DECODE(SIGN(capacity-12),-1,Less than 12,Greater than or equal to 12)
    The Decode can be used inside Decode(nested Decode) in above steps to compare more than one values (range between) to get the desired result. Hope have made it clear enough. If not, please let me know.
    Cheers.
    Yogesh D.

  • Decode Statement Inside the Case statement

    Can we use Decode Statement inside a CASE Statement as show below --
    It is giving an error -- Is the a better way to write with out any error
    create or replace
    function test (a varchar2) RETURN VARCHAR2
    is
    m varchar2(20);
    begin
    m :=
    CASE
    WHEN a IN (
    '1009' -- (soon obsolete)
    ,'1010'
    ,'1019'
    ,'1051'
    ,'XGP'
    ,'XSC')
    THEN (SELECT DECODE(v_lef_cd,'NAM','71','GLB','99','01') into m FROM DUAL)
    -- ) THEN '01' -- UNITED STATES OF AMERICA
    WHEN a IN (
    '1069' -- South Africa
    ,'SAO' -- South Africa
    ,'SA' -- South Africa
    ) THEN '26' -- South Africa
    ELSE NULL
    END;
    return m;
    end;

    Hi,
    You can only use DECODE in SQL statements.
    Your SELECT DECODE (...) INTO statement would work anywhere a PL/SQL statement is allowed; but PL/SQL statements are not allowed within CASE expressions.
    Remember, the expression that comes after THEN in a CASE expression must be a single value.
    I would write a function like this using IF ... ELSIF statements. It's a little more typing than CASE, but a lot easier to code, test and maintain.
    If you want to use CASE, here's one way:
    ...     m := CASE
              WHEN  a  IN ('1069', 'SAO', 'SA')
                   THEN  '26'     -- South Africa
              WHEN  a  NOT IN ('1009', '1019', '1051', 'XGP', 'XSC')
              OR    a  IS NULL
                   THEN  NULL
              WHEN  v_lef_cd = 'NAM'
                   THEN  '71'
              WHEN  v_lef_cd = 'GLB'
                   THEN  '99'
                   ELSE  '01'     -- USA
              END;This assumes that you have a variable v_lef_cd defined.
    If you want, you can nest CASE expressions, like this:
    ...     m := CASE
              WHEN  a  IN ('1069', 'SAO', 'SA')
                   THEN  '26'     -- South Africa
              WHEN  a  IN ('1009', '1019', '1051', 'XGP', 'XSC')
                   THEN  CASE  v_lef_cd
                          WHEN  'NAM'
                             THEN  '71'
                          WHEN  'GLB'
                             THEN  '99'
                             ELSE  '01'     -- USA
                         END
              END;Always format your code, so you can see where the CASE expressions and each of the WHEN clauses begin and end.
    When posting formatted text on this site, type these 6 characters:
    (all small letters, inside curly brackets) before and after sections of formatted text, to preserve spacing.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • DECODE Statement and argument limitations

    Does anyone know the number of arguments that the DECODE statement will allow you to enter. I currently have 863 and it gives me an error message when i try and run the query.
    Database Error - ORA-00939: too many arguments for function.
    Thanks
    Chris

    I dont have the rights to create/edit database, just pull data from it.
    Here is my attempt at the nest, but i stil get the error message about size.
    DECODE(
    DECODE(Point Of Sales His.End User Baan Account,'4260','Croteau; Mark','5001','Croteau; Mark','10714','Croteau; Mark','11966','Croteau; Mark','13739','Croteau; Mark','16233','Croteau; Mark','16736','Croteau; Mark','17276','Croteau; Mark','17377','Croteau; Mark','17387','Croteau; Mark','17436','Croteau; Mark','17452','Croteau; Mark','17485','Croteau; Mark','17681','Croteau; Mark','17741','Croteau; Mark','17794','Croteau; Mark','17799','Croteau; Mark','19364','Croteau; Mark','19462','Croteau; Mark','20205','Croteau; Mark','20995','Croteau; Mark','21916','Croteau; Mark','22269','Croteau; Mark','22629','Croteau; Mark','23562','Croteau; Mark','24078','Croteau; Mark','24079','Croteau; Mark','24550','Croteau; Mark','24796','Croteau; Mark','25196','Croteau; Mark','25506','Croteau; Mark','31494','Croteau; Mark','38067','Croteau; Mark','750457','Croteau; Mark'),
    DECODE(Point Of Sales His.End User Baan Account,'314','Bruning; Barbara','500','Bruning; Barbara','3601','Bruning; Barbara','4142','Bruning; Barbara','4433','Bruning; Barbara','8219','Bruning; Barbara','8584','Bruning; Barbara','13839','Bruning; Barbara','15195','Bruning; Barbara','15307','Bruning; Barbara','15523','Bruning; Barbara','16394','Bruning; Barbara','16529','Bruning; Barbara','17111','Bruning; Barbara','17410','Bruning; Barbara','17471','Bruning; Barbara','19158','Bruning; Barbara','19219','Bruning; Barbara','20219','Bruning; Barbara','20308','Bruning; Barbara','20687','Bruning; Barbara','22364','Bruning; Barbara','22895','Bruning; Barbara','23411','Bruning; Barbara','23983','Bruning; Barbara','24343','Bruning; Barbara','24890','Bruning; Barbara','25828','Bruning; Barbara','25866','Bruning; Barbara','32850','Bruning; Barbara','38046','Bruning; Barbara','38048','Bruning; Barbara','38049','Bruning; Barbara','38051','Bruning; Barbara','38192','Bruning; Barbara','38237','Bruning; Barbara'),
    DECODE(Point Of Sales His.End User Baan Account,'7781','Weber; Ed','8668','Weber; Ed','9016','Weber; Ed','12219','Weber; Ed','12669','Weber; Ed','13200','Weber; Ed','13529','Weber; Ed','13704','Weber; Ed','15453','Weber; Ed','16643','Weber; Ed','17127','Weber; Ed','17399','Weber; Ed','17400','Weber; Ed','17480','Weber; Ed','18064','Weber; Ed','18267','Weber; Ed','18914','Weber; Ed','20121','Weber; Ed','20177','Weber; Ed','21523','Weber; Ed','22155','Weber; Ed','22347','Weber; Ed','31405','Weber; Ed','31445','Weber; Ed','31542','Weber; Ed','31545','Weber; Ed','31696','Weber; Ed','31830','Weber; Ed','31960','Weber; Ed','32818','Weber; Ed','33111','Weber; Ed','34060','Weber; Ed','38061','Weber; Ed','38062','Weber; Ed','38063','Weber; Ed','38208','Weber; Ed','38213','Weber; Ed'),
    DECODE(Point Of Sales His.End User Baan Account,'3455','Rogers; Mary Jill','6854','Rogers; Mary Jill','7277','Rogers; Mary Jill','7376','Rogers; Mary Jill','8223','Rogers; Mary Jill','8645','Rogers; Mary Jill','12063','Rogers; Mary Jill','15449','Rogers; Mary Jill','16086','Rogers; Mary Jill','16782','Rogers; Mary Jill','16940','Rogers; Mary Jill','17036','Rogers; Mary Jill','17232','Rogers; Mary Jill','17285','Rogers; Mary Jill','17316','Rogers; Mary Jill','17430','Rogers; Mary Jill','17462','Rogers; Mary Jill','17656','Rogers; Mary Jill','20015','Rogers; Mary Jill','20277','Rogers; Mary Jill','23184','Rogers; Mary Jill','23318','Rogers; Mary Jill','23387','Rogers; Mary Jill','23388','Rogers; Mary Jill','23689','Rogers; Mary Jill','23696','Rogers; Mary Jill','24157','Rogers; Mary Jill','24219','Rogers; Mary Jill','24336','Rogers; Mary Jill','24676','Rogers; Mary Jill','24681','Rogers; Mary Jill','24793','Rogers; Mary Jill','24827','Rogers; Mary Jill','25038','Rogers; Mary Jill','25245','Rogers; Mary Jill','25281','Rogers; Mary Jill','25416','Rogers; Mary Jill','25417','Rogers; Mary Jill','25418','Rogers; Mary Jill','25419','Rogers; Mary Jill','25420','Rogers; Mary Jill','25421','Rogers; Mary Jill','25422','Rogers; Mary Jill','25423','Rogers; Mary Jill','25424','Rogers; Mary Jill','25425','Rogers; Mary Jill','25426','Rogers; Mary Jill','25427','Rogers; Mary Jill','25428','Rogers; Mary Jill','25429','Rogers; Mary Jill','25430','Rogers; Mary Jill','25431','Rogers; Mary Jill','25432','Rogers; Mary Jill','25433','Rogers; Mary Jill','25434','Rogers; Mary Jill','25435','Rogers; Mary Jill','25436','Rogers; Mary Jill','25437','Rogers; Mary Jill','25438','Rogers; Mary Jill','25439','Rogers; Mary Jill','25440','Rogers; Mary Jill','25441','Rogers; Mary Jill','25442','Rogers; Mary Jill','25443','Rogers; Mary Jill','25444','Rogers; Mary Jill','25445','Rogers; Mary Jill','25446','Rogers; Mary Jill','25447','Rogers; Mary Jill','25448','Rogers; Mary Jill','25449','Rogers; Mary Jill','25450','Rogers; Mary Jill','25451','Rogers; Mary Jill','25452','Rogers; Mary Jill','25453','Rogers; Mary Jill','25454','Rogers; Mary Jill','25455','Rogers; Mary Jill','25456','Rogers; Mary Jill','25457','Rogers; Mary Jill','25458','Rogers; Mary Jill','25459','Rogers; Mary Jill','25460','Rogers; Mary Jill','25461','Rogers; Mary Jill','25462','Rogers; Mary Jill','25463','Rogers; Mary Jill','25464','Rogers; Mary Jill','25465','Rogers; Mary Jill','25466','Rogers; Mary Jill','25467','Rogers; Mary Jill','25468','Rogers; Mary Jill','25469','Rogers; Mary Jill','25470','Rogers; Mary Jill','25471','Rogers; Mary Jill','25472','Rogers; Mary Jill','25473','Rogers; Mary Jill','25474','Rogers; Mary Jill','25475','Rogers; Mary Jill','25476','Rogers; Mary Jill','25477','Rogers; Mary Jill','25478','Rogers; Mary Jill','25479','Rogers; Mary Jill','25488','Rogers; Mary Jill','25489','Rogers; Mary Jill','25522','Rogers; Mary Jill','25532','Rogers; Mary Jill','25541','Rogers; Mary Jill','25547','Rogers; Mary Jill','25570','Rogers; Mary Jill','25775','Rogers; Mary Jill','25845','Rogers; Mary Jill','25875','Rogers; Mary Jill','32164','Rogers; Mary Jill','33328','Rogers; Mary Jill','33844','Rogers; Mary Jill','38057','Rogers; Mary Jill','38060','Rogers; Mary Jill'),
    DECODE(Point Of Sales His.End User Baan Account,'4188','Gallo; Peter','7520','Gallo; Peter','8371','Gallo; Peter','9524','Gallo; Peter','9647','Gallo; Peter','10768','Gallo; Peter','12788','Gallo; Peter','15248','Gallo; Peter','16641','Gallo; Peter','17284','Gallo; Peter','17330','Gallo; Peter','17331','Gallo; Peter','17332','Gallo; Peter','17333','Gallo; Peter','17334','Gallo; Peter','17335','Gallo; Peter','17336','Gallo; Peter','17347','Gallo; Peter','17431','Gallo; Peter','17598','Gallo; Peter','17763','Gallo; Peter','17801','Gallo; Peter','18529','Gallo; Peter','19071','Gallo; Peter','19328','Gallo; Peter','19572','Gallo; Peter','21003','Gallo; Peter','22975','Gallo; Peter','23548','Gallo; Peter','23562','Gallo; Peter','23985','Gallo; Peter','24088','Gallo; Peter','25665','Gallo; Peter','32145','Gallo; Peter','32905','Gallo; Peter','38053','Gallo; Peter','38059','Gallo; Peter','38070','Gallo; Peter','38071','Gallo; Peter','38072','Gallo; Peter','38200','Gallo; Peter'),
    DECODE(Point Of Sales His.End User Baan Account,'142','Coady; Ed','1291','Coady; Ed','2420','Coady; Ed','7726','Coady; Ed','9334','Coady; Ed','10678','Coady; Ed','11487','Coady; Ed','12052','Coady; Ed','12223','Coady; Ed','15386','Coady; Ed','15597','Coady; Ed','16245','Coady; Ed','17277','Coady; Ed','17278','Coady; Ed','17469','Coady; Ed','17674','Coady; Ed','17675','Coady; Ed','17731','Coady; Ed','17826','Coady; Ed','18500','Coady; Ed','18791','Coady; Ed','19035','Coady; Ed','19100','Coady; Ed','19130','Coady; Ed','19131','Coady; Ed','19132','Coady; Ed','19133','Coady; Ed','19134','Coady; Ed','19135','Coady; Ed','19136','Coady; Ed','19137','Coady; Ed','19138','Coady; Ed','19139','Coady; Ed','19140','Coady; Ed','19141','Coady; Ed','19142','Coady; Ed','19143','Coady; Ed','19144','Coady; Ed','19145','Coady; Ed','19146','Coady; Ed','19147','Coady; Ed','19148','Coady; Ed','19149','Coady; Ed','19150','Coady; Ed','19151','Coady; Ed','19152','Coady; Ed','19175','Coady; Ed','19300','Coady; Ed','19533','Coady; Ed','19999','Coady; Ed','20900','Coady; Ed','21020','Coady; Ed','21053','Coady; Ed','21144','Coady; Ed','21470','Coady; Ed','21665','Coady; Ed','21720','Coady; Ed','21731','Coady; Ed','22829','Coady; Ed','22841','Coady; Ed','23457','Coady; Ed','24243','Coady; Ed','24257','Coady; Ed','24345','Coady; Ed','24383','Coady; Ed','25184','Coady; Ed','25354','Coady; Ed','25777','Coady; Ed','25865','Coady; Ed','30181','Coady; Ed','31349','Coady; Ed','38052','Coady; Ed','38224','Coady; Ed'),
    DECODE(Point Of Sales His.End User Baan Account,'1106','Saale; Thomas','2726','Saale; Thomas','6840','Saale; Thomas','7785','Saale; Thomas','7834','Saale; Thomas','8464','Saale; Thomas','8843','Saale; Thomas','8897','Saale; Thomas','9074','Saale; Thomas','9809','Saale; Thomas','10259','Saale; Thomas','10301','Saale; Thomas','10313','Saale; Thomas','10314','Saale; Thomas','10604','Saale; Thomas','10662','Saale; Thomas','10788','Saale; Thomas','10789','Saale; Thomas','10790','Saale; Thomas','10791','Saale; Thomas','10792','Saale; Thomas','10793','Saale; Thomas','10794','Saale; Thomas','10795','Saale; Thomas','10796','Saale; Thomas','10798','Saale; Thomas','10799','Saale; Thomas','10800','Saale; Thomas','10801','Saale; Thomas','10802','Saale; Thomas','10803','Saale; Thomas','10804','Saale; Thomas','10805','Saale; Thomas','10806','Saale; Thomas','10807','Saale; Thomas','10808','Saale; Thomas','10809','Saale; Thomas','10810','Saale; Thomas','10811','Saale; Thomas','10812','Saale; Thomas','10813','Saale; Thomas','10814','Saale; Thomas','10815','Saale; Thomas','10816','Saale; Thomas','10817','Saale; Thomas','10818','Saale; Thomas','10819','Saale; Thomas','10820','Saale; Thomas','10821','Saale; Thomas','10822','Saale; Thomas','10823','Saale; Thomas','10824','Saale; Thomas','10825','Saale; Thomas','10826','Saale; Thomas','10827','Saale; Thomas','10828','Saale; Thomas','10829','Saale; Thomas','10830','Saale; Thomas','10831','Saale; Thomas','10832','Saale; Thomas','10833','Saale; Thomas','10834','Saale; Thomas','10835','Saale; Thomas','10836','Saale; Thomas','10837','Saale; Thomas','10838','Saale; Thomas','10839','Saale; Thomas','10840','Saale; Thomas','10841','Saale; Thomas','10842','Saale; Thomas','10843','Saale; Thomas','10845','Saale; Thomas','10846','Saale; Thomas','10853','Saale; Thomas','10854','Saale; Thomas','10855','Saale; Thomas','10856','Saale; Thomas','10858','Saale; Thomas','10859','Saale; Thomas','10860','Saale; Thomas','10906','Saale; Thomas','10916','Saale; Thomas','10960','Saale; Thomas','11012','Saale; Thomas','11420','Saale; Thomas','11723','Saale; Thomas','11872','Saale; Thomas','11939','Saale; Thomas','11940','Saale; Thomas','11941','Saale; Thomas','12650','Saale; Thomas','12657','Saale; Thomas','12717','Saale; Thomas','12749','Saale; Thomas','12756','Saale; Thomas','12792','Saale; Thomas','12847','Saale; Thomas','12969','Saale; Thomas','13063','Saale; Thomas','13323','Saale; Thomas','13413','Saale; Thomas','13433','Saale; Thomas','13475','Saale; Thomas','13493','Saale; Thomas','13754','Saale; Thomas','13859','Saale; Thomas','14204','Saale; Thomas','14612','Saale; Thomas','14615','Saale; Thomas','14748','Saale; Thomas','15147','Saale; Thomas','15149','Saale; Thomas','15473','Saale; Thomas','15551','Saale; Thomas','15613','Saale; Thomas','15659','Saale; Thomas','15872','Saale; Thomas','15891','Saale; Thomas','16360','Saale; Thomas','16837','Saale; Thomas','16849','Saale; Thomas','16909','Saale; Thomas','16981','Saale; Thomas','17048','Saale; Thomas','17153','Saale; Thomas','17402','Saale; Thomas','17833','Saale; Thomas','18095','Saale; Thomas','18226','Saale; Thomas','18342','Saale; Thomas','18900','Saale; Thomas','19331','Saale; Thomas','19651','Saale; Thomas','19667','Saale; Thomas','19850','Saale; Thomas','19856','Saale; Thomas','20054','Saale; Thomas','20069','Saale; Thomas','20120','Saale; Thomas','20454','Saale; Thomas','20753','Saale; Thomas','20758','Saale; Thomas','20765','Saale; Thomas','21860','Saale; Thomas','22062','Saale; Thomas','22548','Saale; Thomas','22772','Saale; Thomas','22966','Saale; Thomas','22972','Saale; Thomas','22989','Saale; Thomas','23623','Saale; Thomas','23816','Saale; Thomas','23817','Saale; Thomas','23893','Saale; Thomas','24014','Saale; Thomas','24022','Saale; Thomas','24122','Saale; Thomas','24158','Saale; Thomas','24179','Saale; Thomas','24248','Saale; Thomas','24329','Saale; Thomas','24338','Saale; Thomas','24366','Saale; Thomas','24481','Saale; Thomas','24517','Saale; Thomas','24611','Saale; Thomas','24618','Saale; Thomas','24816','Saale; Thomas','24820','Saale; Thomas','24880','Saale; Thomas','24924','Saale; Thomas','24925','Saale; Thomas','24936','Saale; Thomas','24985','Saale; Thomas','24998','Saale; Thomas','25191','Saale; Thomas','25326','Saale; Thomas','25327','Saale; Thomas','25598','Saale; Thomas','25821','Saale; Thomas'),
    DECODE(Point Of Sales His.End User Baan Account,'620753','Saale; Thomas','620758','Saale; Thomas','620765','Saale; Thomas','623816','Saale; Thomas','623817','Saale; Thomas','624014','Saale; Thomas','624022','Saale; Thomas','624248','Saale; Thomas','624329','Saale; Thomas','624816','Saale; Thomas','624880','Saale; Thomas','625598','Saale; Thomas','899998','Saale; Thomas','E99998','Saale; Thomas','UPS001','Saale; Thomas'),
    'Other')

  • Nested IF statement in outline

    We're using 6.2 and I've built a formula into my outline. I have used IF statements before in the outline with no problem. But I'm now trying to use a nested IF statement. Is it possible? Has anyone had any success? I keep getting "unknown calculation type [0} during the dynamic calculation.     if(@ISCHILD ("MERCH DEPTS") and a40000>0);               "hrs - required"=a40000/"sales/hr";          else          if(d0044);               "hrs - required"=25;          else               "hrs - required"=50;                                   endif;                    endif;          TIARod

    I'm not sure if I completely understand what you are doing but I saw a few errors in you is statement. On your else if, you can make elseif but you don't have any function on the member name. I guesed that you need @ismbr, but it could be @isdesc or @ischild???. Take a look at the corrected calc script below. It might help youRegardsif(@ISCHILD ("MERCH DEPTS") and a40000>0);     "hrs - required"=a40000/"sales/hr"; elseif (@ismbr(d0044))     "hrs - required"=25; else           "hrs - required"=50; endif; Glenn S.Narratus Solutions Inc. [email protected]

  • Decode statement in Select line of a View Object Query

    I attempted to create a view object in expert mode with a customized query.
    The query had a decode statement in the select line of the query. The view
    object compiled correctly but gave an error when run.
    ex: select .... decode(CrpSchools.SCHOOLS_ID,null,CrpCustSchools.SCHOOL_NAME,CrpSchools.SCHOOL_NAME) SCHOOL_VALUE, ...
    from ....
    where ....
    The error was that school_value does not exist in the statement. I got the error when
    doing a vo.executeQuery().
    When I removed the decode statement everything worked correctly. Does anyone know if
    the decode statement cannont be used in the select line of a query in a view object?
    Or maybe I was linking the query column (SCHOOLS_ID) up to the view attribute (SCHOOL_VALUE) incorrectly in the
    Attribute Mappings tab of the VO wizard?

    There should be no problem using a DECODE() statement, provided that you've aliases the column as you have done.
    At design time, if you click on the (Test) button, does your query test ok?
    Are you by chance applying a custom where clause at runtime?
    If so, are you saying:
    setWhereClause("yourtable.column_alias = ?";
    or are you doing:
    setWhereClause("column_alias = ?";
    for an expert-mode query, you'll need to use the latter syntax.

  • Logical Standby SQL Apply Using Incorrect Decode Statement

    We are seeing statements erroring out on our logical standby that have been rewritten (presumably by sql apply) with decode statements that don't appear to be correct. For example, here is one of the rewritten statements.
    update /*+ streams restrict_all_ref_cons */ "CADPROD"."OMS_SQL_STATEMENT" p
    set *"APPLICATION"=decode(:1,'N',"APPLICATION",:2)*,
    "STATEMENT"=dbms_reputil2.get_final_lob(:3,"STATEMENT",:4)
    where (:5='N' or(1=1 and (:6='N' or(dbms_lob.compare(:7,"STATEMENT")=0)or(:7 is null and "STATEMENT" is null)))) and(:8="APPLICATION")
    The problem comes in, we believe, with the attempt to write the value "APPLICATION" to the application column which is only a 10 character field. the value for the :1 bind variable is "N" and the value for :2 is null.
    We see the following error on the logical standby:
    ORA-00600: internal error code, arguments: [kgh_heap_sizes:ds], [0x01FCDBE60], [], [], [], [], [], []
    ORA-07445: exception encountered: core dump [ACCESS_VIOLATION] [kxtoedu+54] [PC:0x2542308] [ADDR:0xFFFFFFFFFFFFFFFF] [UNABLE_TO_READ] []
    ORA-12899: value too large for column "CADPROD"."OMS_SQL_STATEMENT"."APPLICATION" (actual: 19576, maximum: 10)
    Is this a configuration issue or is it normal for SQL Apply to convert statements from logminer into decode statements?
    We have an Oracle 10.2.0.4 database running on windows 2003 R2 64-bit os. We have 3 physical and 2 logical standby's, no problems on the physical standbys.

    Hello;
    I noticed some of your parameters seem to be wrong.
    fal_client - This is Obsolete in 11.2
    You have db_name='test' on the Standby, it should be 'asadmin'
    fal_server=test is set like this on the standby, it should be 'asadmin'
    I might consider changing VALID_FOR to this :
    VALID_FOR=(ONLINE_LOGFILES,ALL_ROLES)Would review 4.2 Step-by-Step Instructions for Creating a Logical Standby Database of Oracle Document E10700-02
    Document 278371.1 is showing its age in my humble opinion.
    -----Wait on this until you fix your parameters----------------------
    Try restarting the SQL Apply
    ALTER DATABASE START LOGICAL STANDBY APPLY IMMEDIATEI don't see the parameter MAX_SERVERS, try setting it to 8 times the number of cores.
    Use these statements to trouble shoot :
    SELECT NAME, VALUE, UNIT FROM V$DATAGUARD_STATS;
    SELECT NAME, VALUE FROM V$LOGSTDBY_STATS WHERE NAME LIKE ;TRANSACTIONS%';
    SELECT COUNT(1) AS IDLE_PREPARERS FROM V$LOGSTDBY_PROCESS WHERE
    TYPE = 'PREPERER' AND STATUS_CODE = 16166;Best Regards
    mseberg
    Edited by: mseberg on Feb 14, 2012 7:37 AM

  • How to determine INT and FLOAT in a DECODE statement

    Can anyone help me with the following problem:
    I have a column defined as a NUMBER(15,4). I am trying to determine the java type using the getScale() method in ResultSetMetaData. When the scale is greater than 0, then it is an float, else it is an int. In this case, the getScale() method should return 4. However, when querying with a DECODE statement on the NUMBER(15,4) field, the getScale() method always returns 0 and the value is therefore converted to an int. Anyone knows how to solve this problem?
    Thanks

    Alcides,
    Oracle NUMBER data type is mapped to "java.math.BigDecimal" class.
    You will find more information in the JDBC Developer's Guide and Reference which is part of the Oracle documentation and available from:
    http://www.oracle.com/technology/documentation/index.html
    Good Luck,
    Avi.

  • Need help on decode statement

    I had the table as follows :
    ITEMCODE TEDCODE AMOUNT
    AAAA BED 12345
    AAAA EDU CESS 1234
    AAAA SHECESS 123
    AAAA CST 3% 12456
    AND SO ON.
    Now i want to convert the rows in Column heading TEDCODE to columns. But i want the specific rows like BED, EDU CESS, SHECESS in one column suppose EXCISE, and the other row i.e CST 3% in other column under heading TAX.
    Please help me how i can do it using Decode statement.

    SQL> create table t (itemcode varchar(4),tedcode varchar(10),amount number);
    Table created.
    SQL> insert into t values('AAAA','BED',12345);
    1 row created.
    SQL> insert into t values('AAAA','EDU CESS',1234);
    1 row created.
    SQL> insert into t values('AAAA','SHECESS',123);
    1 row created.
    SQL> insert into t values('AAAA','CST 3%',12456);
    1 row created.
    SQL> select itemcode, tedcode,decode(tedcode,'CST 3%',null,amount) EXCISE, decod
    e(tedcode,'CST 3%',amount,null) TAX from t;
    ITEM TEDCODE    EXCISE                                          TAX
    AAAA BED        12345
    AAAA EDU CESS   1234
    AAAA SHECESS    123
    AAAA CST 3%                                                   12456

  • Is it possible to nest SELECT statements?

    Greetings community,
    Another newbie’s question it is. Looking tutorials and some posts here I’ve been advised not to pull entire table through the local network, and torture client machines’ processors and memory. It’s been said that better solution is to
    pull just one part of the table.
    So, imagine this: you want to make a part of your app that would allow your user to view list of orders. So you put one data grid view on the form, pull last 20 headers from the table into it and leave to user to choose one to be opened
    in another form. If user doesn’t find header they want, they press page up for example and previous 20 headers are loaded into data grid view. Of course, user could filter headers list by customer, or by distribution lane (having all customers residing in
    one part of the town), or whatever more, but let’s not complicate things at this moment, because I’m practically in the beginning.
    I’m trying to make a stored procedure that would load penultimate 20 headers when user presses page up. So, not knowing any better, I created table variable that has the same structure as Orders table with one difference: OrderID column,
    which is identity (auto incremented) in Orders table, here is simply defined as bigint not null. Community member Visakh16 warned me few months ago it’s the bad practice to put self-incrementing columns in table variables.
    At this moment there’s a query on my screen, which waits to become store procedure. After boring part with table variable definition, it goes like this:
    INSERT INTO @OrdersTemp SELECT TOP 40 * FROM dbo.Orders ORDER BY OrderID DESC
    SELECT TOP 20 * FROM @OrdersTemp ORDER BY OrderID ASC
    To put that simply, I pull last 40 headers into table variable, and then pull first 20 from there. This thing works, and I just have to replace 40 with parameter, for every page up or down.
    Now I have few questions.
    -Is there some better way (considering performance) to achieve that? Here is the place where I wanted to ask the question from the title of the post. I don’t know much about T-SQL, and I’m not sure about the proper syntax to nest SELECT
    statements, if something like that is even possible
    -Is there any better way (some built-in function) to find about the count of the rows in one table than
    SELECT COUNT(OrdersID) FROM dbo.Orders
    Thanks for any suggestions.

    Hi Erland,
    Sorry for the very late reply, but I said that I would start another thread when I find more free time to dedicate it to this, so I didn’t really expected you to reply anymore. I didn’t really check here for more than a week, and I glanced
    at mail accidentally.
    As for the negative result I got, its measurement unit is microsecond, so it doesn’t go out of margins you had experienced.
    As for the number of cores, you got me surprised there. I use express edition of SQL server. Last time I checked was SQL server 2012 express, and in specifications it said that express edition is limited to 1 processor core, 1GB of RAM
    and creates up to 10GB database file. I don’t believe they changed any of those specifications. It was generous enough when they doubled size of DB file few editions ago. Still, it appears that “one processor core for express edition” statement has some gray
    areas in it.
    However, at this moment I’m just learning, and I just wanted some way to test how efficient my queries are. I don’t have a real biz problem to solve. I don’t expect that any real performance problem should rise in years of everyday work
    of populating database. What I expect is performance impact when it comes to creating reports, but after all, I don’t think that my boss would create reports by himself. I believe that creating reports would be my task, and I will be doing it after hours,
    being the only user at the moment. Or maybe I could make de-normalized copy of database that would be populated after hours to make it possible for my boss to get his reports faster by himself, as I’ve heard that was the way of making BI in older non-express
    editions.
    So, I do suggest that we finally close this thread for sake of other readers. I’ll start another one with this subject when I find the time to do it.
    Again, thanks for being with me along this journey.

  • Nested SQL statements for complex, detailed queries.

    Is it  possible to write nested SQL statements for complex, detailed queries. A nested query
    has a WHERE clause that includes a SELECT statement ? Is it true or false ?

    Hi wahid,
    Here are pretty good examples: 
    http://www.databasejournal.com/features/mssql/article.php/3464481/Using-a-Subquery-in-a-T-SQL-Statement.htm
    http://technet.microsoft.com/en-us/library/aa213252(v=sql.80).aspx
    Regards Harsh

  • Calling a stored proc in a decode statement

    I am having a problem calling a store procedure in a SQL statement. I am using Oracle's thin driver.
    I have been able to do the following:
    select col1,
    col2,
    SOME_STORED_PROC(var1,var2,col3)
    from some_table
    where col3 = var3
    However, when I try to call a stored procedure with-in a decode statement, the call fails. I have tested the call from a sql prompt and it works fine but it does not work when I execute the query in my Java program.
    Here is an example of what I am trying to do:
    select col1,
    col2,
    decode((select col1
    from some_other_table
    where col2 = var1), 'X',
    SOME_STORED_PROC(var1,var2,col3),
    SOME_OTHER_STORED_PROC(var2,var4,col5))
    from some_table
    where col3 = var3
    Does anyone know if this type of call is not supported in Oracle's thin driver?
    Thanks,
    Cory
    null

    I played around with a [parallel PL/SQL launcher|http://www.williamrobertson.net/feed/2008/08/parallel-plsql-launcher-update.html] a while ago, but I wouldn't call it production-ready.
    You could also [submit procedure calls in background|http://www.williamrobertson.net/feed/2005/12/job-control-object.html] using DBMS_ALERT to track completion status.

  • Problem with Decode statement

    Hi
    I am trying to achieve the following in my report:
    If an employee has a surname of . (dot) or a first name of . (dot), the report should not display a dot. An employee's name is made up of surname, first name and middle name which should all be concatenated together. To try to achieve this, I have the following statement in my report:
    decode(e.Surname, '.', ( LTRIM(RTRIM((INITCAP(e.FIRST_NAME)))||' '||INITCAP(e.MIDDLE_NAME)) ) ,
    e.FIRST_NAME, '.', ( LTRIM(RTRIM((INITCAP(e.Surname)))||' '||INITCAP(e.MIDDLE_NAME)) ) ,
    ( LTRIM(RTRIM((INITCAP(e.SURNAME )))||', '||INITCAP(e.FIRST_NAME)||' '||INITCAP(e.MIDDLE_NAME)) ) ) as emp_name
    FROM Employee e
    Problem: The above statement is only working for those employees with surname of . (dot). It's not working for first names of dot. How can I use the decode statement OR is there any other way of doing it without using the CASE statement?
    It seems my decode statement doesn't work with 2 different fields (surname, firstname) being tested within one decode statement.Thanks.

    Thank you so much InoL . I have used the ltrim with Replace but now have a new problem.
    Because I am joining Surname, First name and middle name together and put a comma after the Surname, the name now appears as follows:
    , Maria Ane (if Surname is a dot)
    Boiler, (if first name is a dot)
    I would like to get rid of a comma and only have comma when surname or first name does not have a dot, i.e. for those people with full names e.g. Blake, Anna Marie.
    InoL, how can I achieve this? Thanks.

Maybe you are looking for