concatenating whole so so otherwise - matter or decode statements

Hello

I have a table called t_criteria of columns 'criterion_1', 'criterion_2' and criterion_3' with line for each column being either 'Yes', 'No' or 'not known '. (See the DOF below)

What I want is a statement that will give the number of criteria which have been fulfilled (i.e. the line 'Yes') in a list separated by commas in a column called 'criteria_met '.

I know how to do this in excel but do not know how I would go about it in oracle?

It is a way to do this in excel:

"= SUBSTITUTE (TRIM (IF(B2="Yes",1,)" ") &" "& IF(C2="Yes",2,)" "") &"" & IF(D2="yes",3,) "" ")),""," ")"

When column B is criterion_1, column C is criterion_2 and column D is criterion_3.

I use the database 11g r2


create the table t_criteria

(the number (2) of site_id not null,)

criterion_1 varchar2 (25).

criterion_2 varchar2 (25).

criterion_3 varchar2 (25).

key primary constraint site_id_pk (site_id)

);

-----------------

insert into t_criteria values (1, 'Yes', 'No', ' yes');

insert into t_criteria values (2, 'Yes', 'No', "Ignore");

insert into t_criteria values (3, 'Yes', 'No', ' yes');

insert into t_criteria values (4, 'No', 'Yes', ' don't know');

insert into t_criteria values (5, 'No', "Don't know", "Ignore");

insert into t_criteria values (6, 'No', 'No', ' yes');

insert into t_criteria values (7, 'No', "Don't know", "Ignore");

insert into t_criteria values (8, 'Yes', 'No', "Ignore");

insert into t_criteria values (9, 'Yes', 'No', "Ignore");

insert into t_criteria values (10, 'Yes', 'No', "Ignore");

insert into t_criteria values (11, 'No', 'No', "ignore");

Hello

Please try below script

SELECT REPLACE (TRIM(' ')

OF DECODE(criterion_1,'Yes',1,'')

||' '

|| Decode(criterion_2,'Yes',1,'')

||' '

|| (Decode(criterion_2,'Yes',1,'')), "","")

OF t_criteria;

Concerning

Mr. Mahir Quluzade

Tags: Database

Similar Questions

  • Problem with Decode statement

    Hello

    I try to do the following in my report:

    If an employee is a family name. (dot) or a name of. (dot), the report does not display a point. An employee name consists of the family name, first name and middle name, which should all be concatenated sets. An attempt to achieve this goal, 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

    E employee

    Problem: The above statement only works for employees with the name of. (dot). It doesn't for the first names of dot. How to use the decode statement OR is there another way to do it without using the CASE statement?

    It seems my decode statement does not work with 2 different fields (name, first name) tested within the decode statement. Thank you.

    LTRIM and RTRIM the comma too:

    select rtrim(ltrim(rtrim(ltrim(', Somename ,',','),','))) Name
    from dual;
    
    NAME
    --------
    Somename
    
  • DECODE statement and the argument limits

    No one knows the number of arguments that the DECODE statement allows you to enter. I currently have 863 and it gives me an error message when I try to run the query.

    Database - ORA-00939 error: too many arguments for the function.

    Thank you
    Chris

    Hello

    You still have too many parameters your decodes, the limit is 250 so you can enter only 124 values and decoded. I would like to nest decodes by doing:

    DECODE (point, "c1", "v1", "c2", "v2", "c3", "v3",..., DECODE (point, 'c4', 'v4', 'c5', 'v5', 'c6', 'v6',..., DECODE (...)))

    Alternatively, you can for example use case

    WHEN BOX point IN ( END)

    Rod West

  • Calculation grouping using decode statement?

    I have 4 sales reps who are numbered 9801, 9802, 9803 VRP, 9804.

    I have 3 support staff that support accounts by virtue of these representatives of REPS 1, 2, 3

    Support rep 1 will support the commercial attaché 9801 & 9802
    Support rep 2 will support the commercial attaché 9802 and 9803
    Support rep 3 will support the commercial attaché 9803 & 9804.

    Initially, I had a report which gave the results for all listed sales reps. The representatives of support and then imported it into excel and delete the records of the sales reps that they do not need.

    I want to create a page filter that will support rep select its name in a drop-down which shows only sales reps they support. So support rep 1 can select their name from the drop down and the report would only show information for the commercial attaché 9801 & 9802.

    I tried to do this with a calculation using the decode statement, but it does not work. It seems only to associate support rep to each sales representative. Is there a way to accomplish the grouping I want?

    DECODE (put into commercial service Rep.Sales,
    9801,'REP ' 1,.
    9802,'REP ' 1,.
    9802, ' REP 2',
    9803, ' REP 2',
    9803, ' REP 3',
    9803, ' REP 4'.
    9804, ' REP 4'.
    "ERROR")

    Hello

    I don't think you can do it easily if you want to use a filter on the page. This is because if a row is returned by the database that has a sales of 9802, then, the line must be on 2 pages.

    You can create a parameter to select the support rep and use this setting to select the records. Therefore, if the parameter is p_support_rep then you have a condition like:

    (: p_support_rep = 'REP1' AND sales_rep IN (9801, 9802)) OR
    (: p_support_rep = "REP2' AND sales_rep IN (9802, 9803)) OR
    (: p_support_rep = "REP2' AND sales_rep IN (9803, 9804))

    If you really need to use a filter on the page, then you will need to use a generator of line to create a line for each support rep and to join your generator line report by using a report similar to the one above. You can search for "Generator line" of this forum, or check out the learndiscoverer blog (http://learndiscoverer.blogspot.com/2008/10/row-generators.html) for more details.

    Rod West

  • Concatenation of strings to form an INSERT INTO statement

    I am trying to build an insert statement by concatenating strings. Basically, that's what I do:
    < cfset string1 = "INSERT INTO #tablename # (" > ").
    < cfset string1 = string1 & #colname # >
    < cfset string1 = string1 & ")" > "
    < cfset string2 = "VALUES ('" > ").
    < cfset string2 = string1 & #coldata # >
    < cfset string2 = string1 & "')" > "

    < cfquery = "insert" datasource name = "db" >
    # String1 string2 # #.
    < / cfquery >


    -----------------------------------------
    Also, if I change the < cfquery > tags to < cfoutput > I get a valid INSERT statement:
    INSERT INTO Habitat (AREA, ARTID, BIOTOP) VALUES (43, 37, ' text')

    But when I have the tag < cfquery > I get this error:
    Syntax error (missing operator) in query expression "' text"'.

    I tried to change the (' #coldata # ') to ("#coldata") and also tried ("#coldata #") and ("' #coldata # '"), but I get errors all the time...

    So. How can I do this?

    I'm not asking why you do this :)

    but you will need to use preserveSingleQuotes(). probably right around string2, but may not be wrong to just wrap the whole.


    #preserveSingleQuotes (string1 & string2) #.

  • BOX WHEN in DECODE statement

    SELECT v_startdate, v_enddate,
    (CASE WHEN SYSDATE BETWEEN v_startdate AND v_enddate THEN
    'active '.
    ON THE OTHER
    'inactive '.
    Status of END)
    OF correction_tab;

    Could you kindly guide as to how to use DECODE and get the desired result.


    Thank you
    Rami Reddy.

    You can, like this.
    However, the CASE seems much clearer for me so why bother with a DECODING?

    sql> with correction_tab as
      2    ( select trunc(sysdate)-1 as v_startdate, trunc(sysdate)   as v_enddate from dual
      3    union all
      4      select trunc(sysdate)   as v_startdate, trunc(sysdate)+1 as v_enddate from dual
      5    union all
      6      select trunc(sysdate)+1 as v_startdate, trunc(sysdate)+2 as v_enddate from dual
      7    )
      8  SELECT v_startdate
      9  ,      v_enddate
     10  ,      CASE
     11           WHEN SYSDATE BETWEEN v_startdate AND v_enddate
     12             THEN 'active'
     13           ELSE 'inactive'
     14         END status
     15  ,      decode ( sign(sysdate-v_startdate), 1, decode(sign(v_enddate-sysdate), 1, 'active', 'inactive'), 'inactive')
     as status2
     16  FROM correction_tab
     17  /
    
    V_STARTDA V_ENDDATE STATUS   STATUS2
    --------- --------- -------- --------
    12-DEC-12 13-DEC-12 inactive inactive
    13-DEC-12 14-DEC-12 active   active
    14-DEC-12 15-DEC-12 inactive inactive
    
  • in the DECODE statement error

    Hello

    I wrote that decode the clause but anyway its not working and giving expression error.
    SELECT 
    ( DECODE
    (
     select param_value from feed_parameter where upper(param_name) = 'SOURCEENV' and feed_id=5085 AND CLOSE_ACTION_ID IS NULL
    ),'NTSNGN','mput \\csng11p20126\risk-mgt$\app\data\rds\PLNMARS4\done\',
      'NTNYC' ,'mput \\nnyc11p20008\risk$\app\data\rds\PLNMARS4\done',
               'DONE PATH') "path"
    )                                   
    FROM feed_parameter;
    Is there any mistake in this expression?
    SELECT
    
    DECODE(PARAM_VALUE,
    'NTSNGN',
    'mput \\csng11p20126\risk-mgt$\app\data\rds\PLNMARS4\done\',
    'NTNYC' ,
    'mput \\nnyc11p20008\risk$\app\data\rds\PLNMARS4\done',
    'DONE PATH') AS PATH
    from feed_parameter
    WHERE UPPER(PARAM_NAME) = 'SOURCEENV'
    AND FEED_ID=5085
    AND CLOSE_ACTION_ID IS NULL
    

    Try it please.

    Published by: Mahir M. Quluzade March 7, 2011 12:28

  • Nesting help DECODE statements

    Hello. I'm writing a sql script to generate the data for payments report. I need to integrate specific to the field of ADDRESS VACUUM lines to REMOVE conditions. I'm using Address_Line1, Address_Line2, Address_Line3, most CITY, STATE, ZIP as Address_Line4. If all fields are empty, I need to remove the blank line and back up the other lines.

    Here is 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;
    /

    Hello

    Interplay says:
    ...
    Here's the script:

    WITH got_delimited_list AS
    (
    SELECT address_line1 || ' +' ||
    address_line2 || ' +' ||
    address_line3 || ' +' ||
    ...
    

    This is equivalent to

    SELECT  (address_line1 || ' ')    || '+' ||
         (address_line2 || ' ')    || '+' ||
         (address_line3 || ' ')    || '+' || ...
    

    You are guaranteeing to all areas will result in a space, and therefore may not be NULL.
    Lose the spaces before the signs +:

    SELECT  address_line1 || '+' ||
         address_line2 || '+' ||
         address_line3 || '+' || ...
    

    Published by: Frank Kulash on Feb 3, 2010 10:04
    Sorry, my fault. My original post had this error.

  • Help to DECODE statement

    Hi all

    I have data like this YEAR, to 2 columns ITEM_ID

    A 001
    B 002
    C 003
    A 006
    Z 010

    I want to interview based on criteria of the user of what rank they needed. for some reason I need if users choose Z as a criterion, I need a list of all elements with the class A.

    SELECT * FROM my_tbl WHERE to rank = DECODE (: userprompt, 'A', 'A', 'B', 'B'...') Z', ??) ;

    ?? -im missing how to set the condition, I tried with "* has" but nothing bowed not, obviously, it ranks = ' * Z' and do not return all rows.

    Oracle 10 G.
    PLS NOTE * = not equal symbol, for some reason, it does not appear when I post the thread.,.

    Thanks in advance.

    Published by: [email protected] on Sep 4, 2008 10:30

    This should do the trick:

    where grade = decode(:userprompt,'Z',translate(grade,'A','x'),:userprompt)
    

    Published by: Sentinel on September 4, 2008 10:36

  • Disqualification - CASE or DECODE statement writing

    Test

    Edited by: user4362313 may 3, 2013 05:00

    Hi Bala,

    If I interpreted the statement correctly, then you are wanting fill the digits left of the decimal point to four characters, so 12.345 becomes 0012.345.

    The best way to achieve this is by using a processor of Expression (see the online help for details of full syntax). Assuming that the input attribute is called 'col1' then the following expression should lead to the desired result:

    substr ('000' | col1, indexof (col1, ".") - 1).

    Kind regards
    Nick

  • Need help in writing the SQL CASE or DECODE statement

    Hi experts,

    I need to write a SQL select order_num, cntry_cde, prod_id and Qty by joining order_num on PROD_ORDER and PROD_ORDER_TXT.

    Here is my sample data

    PROD ORDER_
    order_num Prod_id Qty cntry_cde
    100 US A1 5
    101 US 10 A2
    102 IN A3 4
    103 TO THE A4 9
    104. IN A5 3

    PROD ORDER_TXT_
    cntry_cde Prod_id order_num
    100 US A1
    101 US A2
    102 NZ A3
    103 TO THE A4
    A5 104

    Here's the requirement,

    (1) if the cntry_cde in PROD_ORDER is the same as cntry_cde in PROD_ORDER_TXT then select PROD_ORDER.cntry_cde (orders 100, 101, 103)
    (2) if they are different, choose PROD_ORDER_TXT (order 102, to THE NZ <>) country code
    (3) if they are different and PROD_ORDER_TXT.cntry_cde is null, I can't use it like cntry_cde in my report (order 104). It happenend just because of bad data to the source.
    I can't avoid it. Then just use the cntry_cde of PROD_ORDER

    Expected results
    100 US A1 5
    101 US 10 A2
    102 NZ A3 4 - changed in NZ
    103 TO THE A4 9
    104. IN A5 3 - IN retained as PROD_ORDER_TXT.cntry_cde is null


    instructions for creation and insertion of sample table are lower than

    create the table prod_order
    (number of order_num,
    cntry_cde CHAR (2),
    prod_id VARCHAR2 (6).
    number of quantity)

    create the table prod_order_txt
    (number of order_num,
    cntry_cde CHAR (2),
    prod_id VARCHAR2 (6))

    insert into prod_order values (100, 'WE', 'A1', 5);
    insert into prod_order values (101, 'WE', 'A2', 1);
    insert into prod_order values (102, ' to THE ', 'A3', 4);
    insert into prod_order values (103, ' to THE ', 'A4', 9);
    insert into prod_order values (104, 'IN', 'A5', 3);



    insert into prod_order_txt values (100, 'WE', 'A1');
    insert into prod_order_txt values (101, 'WE', 'A2');
    insert into prod_order_txt values (102, 'NZ', 'A3');
    insert into prod_order_txt values (103, ' to THE ', 'A4');
    insert into prod_order_txt values (104, 'A5', NULL);

    commit;

    Thank you for your help in advance

    Published by: manon March 28, 2012 13:39
  • SELECT with the matter in that statement based on the procedure returning a Boolean

    Hi all

    I try to build a select statement with a case where the condition.
    SELECT COL_ID, COL_TITLE, COL_COMMENT,
               ( CASE WHEN COL_IT = :USER_ID THEN 'Y' 
                           WHEN COL_USER = :USER_ID THEN 'Y'
                           WHEN REGEXP_LIKE(COL_IT_ADD, '(^|:)(' || :USER_ID || ')(:|$)') THEN 'Y'
                           ELSE 'N' END ) MY_COL,
    FROM   MY_TABLE
    WHERE  ( CASE WHEN MY_PACKAGE.AUTHORIZE('IT') = TRUE THEN 'Y'
                           WHEN MY_PACKAGE.AUTHORIZE('IT') = FALSE AND COL_USER = :USER_ID THEN 'Y'
                           WHEN MY_PACKAGE.AUTHORIZE('IT') = TRUE AND  REGEXP_LIKE(COL_IT_ADD, '(^|:)(' || :USER_ID || ')(:|$)') THEN 'Y'
                           ELSE   'N' END ) = 'Y'
    The case for the calculation of the value of the column works fine. Run this query without the where also works in condition.
    But in the condition, I get the following error: SQL error: ORA-00920: invalid relational operator 00920. 00000 - "invalid relational operator.
    The MY_PACKAGE procedure. AUTHORIZED (pValue) returns a Boolean value. Is it possible to use a case statement in the WHERE condition to calculate a value and check for this? If not, is there another way to do something like this in a query?

    Thanks for your help
    Chrissy

    The Boolean data type is unknown in SQL... you cannot use functions that return Boolean values in SQL.

    You can add a function overloaded in the package which returns a 'Y' or a 1, or something else that is a data type in SQL.

  • I think just a matter

    Is there a way to create a sql statement that would be the following.

    TABLE TEST
    columns: name, Id

    example of data

    ID name
    John 1
    John 2
    John 4
    mat 2
    Stephen 4
    Tom 1

    What I'm trying to do is create a query to select all of those wearing the id 1 or 2, and if none is found send me anyone who has only an identifier 4.

    If id = 1 id = 2
    then
    Send results
    otherwise if id = 4
    Send results

    I was wondering if this can be done with a decode statement or not. It sounds simple enough, but I have yet to find the request for her. Any help would be appreciated. Also, I tried something like this on the web, but does not and it seems to be a matter of noobie as well.

    Hello

    The following query Let's manipulate you data as tables without create tables and insert data.

    Kind regards

  • For Windows Media player DVD decoder

    When I put a dvd movie into my satelite A10 it open windows media player and then he says that he cannot find a dvd decoder. What must I do to watch dvd movies?

    Hello

    Watch the movie using a DVD given Toshiba (InterVideo WinDVD). In this case, you have not need no matter what decoder and it will work correctly.

    Good bye

  • Decode the formula to calculate interactive field

    Hello

    Need help to decode formula to calculate interactive field.

    What is the problem with the formula below?
    What I want is...
    If the BH field value is 'Y' then get the field value T to another 'OK '.
    If the value of the T field does not begin with 'FY11 OR %' then get value in field of another 'OK '.
    If the value of field AL ends with "REC" then 'CHECK' otherwise 'OK '.

    DECODE (SUBSTR (decode (SUBSTR (decode (BH, 'Y', T, 'OK'), 1, 7), not as 'FY11 OR %', AL, 'OK'),-3), 'REC', 'CHECK', 'OK')

    I get the error message: invalid calculation expression. not

    Could you please suggest me a correct formula?

    FYI, I use Apex 3.0 which does not support the CASE WHEN THEN END.

    Thank you
    Guy

    Hello

    It is slow when you use functions like this in query

    I don't know how you like it as one more example of

    DECODE(DECODE(SUBSTR(T,1,7),'FY11 OU','OK','NOK') || DECODE(BH || SUBSTR(AL,-3),'YREC','OK','NOK'),'NOKOK','OK','CHECK')
    

    And I'm sure it's still slower

    Kind regards
    Jari

Maybe you are looking for