If-then-else in a select statement

hi, is it possible to make a if-then-else in a select query, something like:
select name, age, if(sex=f,1,2) as my_columnn from table1;
thx.

Hallo,
yes it is possible:
1. with decode
select name, decode(sex, 'f',1,2) as your_column from table1;
2. with case
select name, case when sex='f' THEN 1 ELSE 2 END) as your_column from table1;
Regards
Dmytro

Similar Messages

  • IF-ELSE issue in Select Statement

    Hello,
    I have following query in SQL Server which I am trying to convert to Oracle 11g.
    IF '[Param.1]' = 'S' OR '[Param.1]' = 'T' THEN
    select * from ULQUEUE
    END IF
    But when I write the same query in Oracle, it gives error stating Invalid SQL Statement. So how do I incorporate IF-ELSE in Select Statement in Oracle?
    Edited by: 967327 on Oct 31, 2012 2:01 PM

    Hi,
    First of all, remove asterisk sign from the end of line
    select * from ULQUEUE;* Second: where you try to put this code? This is not SQL, but PL\SQL so you have to have some variable where you want to put query result like this:
    declare
    x ULQUEUE%Rowtype;
    begin
    select *
    into    x
    from ULQUEUE
    end; This of course works when your query returns only one row. Otherwise process data in the loop or put result into array.

  • If else logic in select statement

    Hi,
    Can someone kindly explain me how can i use if-else logic in the place of case statement in the below query.
    SELECT deptno, empno, ename, sal,
                 CASE
                    WHEN deptno = 10
                       THEN sal * 0.05
                    WHEN deptno = 20
                       THEN sal * 0.10
                 END AS new_sal
            FROM emp;Thanks in advance!!

    CREATE OR REPLACE PROCEDURE calsal
    IS
       new_sal number;
       CURSOR sal_cursor
       IS
          SELECT deptno, empno, ename, sal
            FROM emp;
    BEGIN
       FOR i IN sal_cursor
       LOOP
              if i.deptno = 10 then
                   new_sal := i.sal *0.05 ;
               DBMS_OUTPUT.put_line (   ' Salary plus bonus of '
                                || i.empno
                                || ' is '
                                || (new_sal)
           elsif i.deptno = 20 then
                   new_sal := i.sal *0.1 ;
               DBMS_OUTPUT.put_line (   ' Salary plus bonus of '
                                || i.empno
                                || ' is '
                                || (new_sal)
           else
                     new_sal := 0 ;
               DBMS_OUTPUT.put_line (   ' Salary plus bonus of '
                                || i.empno
                                || ' is '
                                || (new_sal)
           end if;
       END LOOP;
    END;
    / Are you learning Oracle or sql or pl/sql ?
    The syntax and example of if in oracle is easily awailable in bunch of documents provided in google search results..
    Regards,
    Dipali..

  • Quick help with a select statement...

    Hello all,
    I will try to lay this out as simply as possible.  I have the following table in my code:
    TYPES: BEGIN OF ty_table,
        vbeln TYPE likp-vbeln,
        lfdat TYPE likp-lfdat,
        lfart TYPE likp-lfart,
        wadat_ist TYPE likp-wadat_ist,
        vstel TYPE likp-vstel,
        route TYPE likp-route,
        vsbed TYPE likp-vsbed,
        inco1 TYPE likp-inco1,
        inco2 TYPE likp-inco2,
        kunnr TYPE likp-kunnr,
        kunag TYPE likp-kunag,
        brgew TYPE lips-brgew,
        matnr TYPE lips-matnr,
        arktx TYPE lips-arktx,
        meins TYPE lips-meins,
        lgmng TYPE lips-lgmng,
        vgbel TYPE lips-vgbel,
        name2 TYPE adrc-name2,
        street TYPE adrc-street,
        city1 TYPE adrc-city1,
        region TYPE adrc-region,
        post_code1 TYPE adrc-post_code1,
        lifnr  TYPE lfa1-lifnr,
        name1 TYPE adrc-name1,
        so_vbeln TYPE vbak-vbeln,
        erdat TYPE vbak-erdat,
      END OF ty_table.
    DATA: it_table TYPE TABLE OF ty_table.
    I then run through a select statement as follows:
    * Get data from LIKP and LIPS.
      SELECT a~vbeln a~lfdat a~lfart a~wadat_ist a~vstel a~route a~vsbed b~brgew a~inco1 a~inco2 a~kunnr a~kunag
               b~matnr b~meins b~lgmng b~vgbel b~arktx INTO CORRESPONDING FIELDS OF TABLE it_table
               FROM likp AS a
                INNER JOIN lips AS b ON b~vbeln = a~vbeln
                WHERE a~vstel IN so_vstel
                AND a~wadat_ist IN so_wadat
                AND b~mtart IN so_mtart.
    That works fine.  The next statement, in the report, is the following select.  When this next select runs it clears all of the fields except for vbeln and erdat.  I want c~vbeln to go into it_table-so_vbeln.  Now it is going into it_table-vbeln.
    * Get Sales order info from VBAK
      SELECT c~vbeln c~erdat INTO CORRESPONDING FIELDS OF TABLE it_table
          FROM lips AS a
            INNER JOIN vbap AS b ON b~vbeln = a~vgbel
            AND b~posnr = a~vgpos
              INNER JOIN vbak AS c ON c~vbeln = b~vbeln
              FOR ALL ENTRIES IN it_table
                WHERE a~vgbel = it_table-vgbel.
    I then tried to write the select statement by takign out "into corresponding fields" like the following but it gives my a syntax error on (it_table-so_vbeln , it_table-erdat).
    * Get Sales order info from VBAK
      SELECT c~vbeln c~erdat INTO (it_table-so_vbeln , it_table-erdat)
        FROM lips AS a
          INNER JOIN vbap AS b ON b~vbeln = a~vgbel
          AND b~posnr = a~vgpos
            INNER JOIN vbak AS c ON c~vbeln = b~vbeln
            FOR ALL ENTRIES IN it_table
              WHERE a~vgbel = it_table-vgbel.
    Is there a way to write the second select (the select that is pulling data from VBAK) so that it will not clear the other entries in the table?  Also, is there a way to combine the two selects into one join? 
    Regards,
    Davis

    Following is the entire report, if that makes it easier:
    *& Report  Z_TRANS_EVAL
    REPORT  z_trans_eval.
    TABLES: likp, lips, adrc, vbpa.
    TYPE-POOLS: truxs.
    TYPES: BEGIN OF ty_table,
        vbeln TYPE likp-vbeln,
        lfdat TYPE likp-lfdat,
        lfart TYPE likp-lfart,
        wadat_ist TYPE likp-wadat_ist,
        vstel TYPE likp-vstel,
        route TYPE likp-route,
        vsbed TYPE likp-vsbed,
        inco1 TYPE likp-inco1,
        inco2 TYPE likp-inco2,
        kunnr TYPE likp-kunnr,
        kunag TYPE likp-kunag,
        brgew TYPE lips-brgew,
        matnr TYPE lips-matnr,
        arktx TYPE lips-arktx,
        meins TYPE lips-meins,
        lgmng TYPE lips-lgmng,
        vgbel TYPE lips-vgbel,
        name2 TYPE adrc-name2,
        street TYPE adrc-street,
        city1 TYPE adrc-city1,
        region TYPE adrc-region,
        post_code1 TYPE adrc-post_code1,
        lifnr  TYPE lfa1-lifnr,
        name1 TYPE adrc-name1,
        so_vbeln TYPE vbak-vbeln,
        erdat TYPE vbak-erdat,
      END OF ty_table.
    DATA: it_table TYPE TABLE OF ty_table,
          wa_table LIKE LINE OF it_table,
          it_table_csv TYPE truxs_t_text_data.
    DATA : lv_tabix LIKE sy-tabix.
    DATA temp_string TYPE string.
    DATA w_adrnr TYPE vbpa-adrnr.
    DATA: w_adrnr_sp TYPE vbpa-adrnr.
    * Selction criteria
    SELECTION-SCREEN BEGIN OF BLOCK b2 WITH FRAME TITLE text-004.
    SELECT-OPTIONS: so_vstel FOR likp-vstel,
                    so_wadat FOR likp-wadat_ist,
                    so_mtart FOR lips-mtart.
    SELECTION-SCREEN END OF BLOCK b2.
    * CSV output filename
    SELECTION-SCREEN BEGIN OF BLOCK b3 WITH FRAME TITLE text-003.
    SELECTION-SCREEN BEGIN OF LINE.
    SELECTION-SCREEN COMMENT (16) text-002 FOR FIELD p_file.
    PARAMETERS: p_file(30) TYPE c.
    SELECTION-SCREEN END OF LINE.
    SELECTION-SCREEN END OF BLOCK b3.
    START-OF-SELECTION.
    * Get data from LIKP and LIPS.
      SELECT a~vbeln a~lfdat a~lfart a~wadat_ist a~vstel a~route a~vsbed b~brgew a~inco1 a~inco2 a~kunnr a~kunag
               b~matnr b~meins b~lgmng b~vgbel b~arktx INTO CORRESPONDING FIELDS OF TABLE it_table
               FROM likp AS a
                INNER JOIN lips AS b ON b~vbeln = a~vbeln
                WHERE a~vstel IN so_vstel
                AND a~wadat_ist IN so_wadat
                AND b~mtart IN so_mtart.
    * Get Sales order info from VBAK
      SELECT c~vbeln c~erdat INTO CORRESPONDING FIELDS OF TABLE it_table
          FROM lips AS a
            INNER JOIN vbap AS b ON b~vbeln = a~vgbel
            AND b~posnr = a~vgpos
              INNER JOIN vbak AS c ON c~vbeln = b~vbeln
              FOR ALL ENTRIES IN it_table
                WHERE a~vgbel = it_table-vgbel.
    * Get internal address number for ship to party
      LOOP AT it_table INTO wa_table.
        lv_tabix = sy-tabix.    "update counter.
        SELECT SINGLE adrnr FROM vbpa INTO w_adrnr WHERE
        vbeln = wa_table-vgbel
        AND parvw = 'WE'.
        SELECT SINGLE lifnr FROM vbpa INTO wa_table-lifnr WHERE
          vbeln = wa_table-vbeln
          AND parvw = 'SP'
          AND  posnr = '000000'.
        SELECT SINGLE name1 FROM lfa1 INTO wa_table-name1 WHERE
          lifnr = wa_table-lifnr.
    * Get address data from VBPA
        SELECT city1 region post_code1 INTO CORRESPONDING FIELDS OF wa_table
        FROM adrc WHERE
        addrnumber = w_adrnr.
        ENDSELECT.
    * Update the internal table
        MODIFY  it_table INDEX lv_tabix FROM wa_table.
      ENDLOOP.
    END-OF-SELECTION.
    * Call correct display procedure(s).
      IF p_file <> ''.
    * Save a CSV file
        PERFORM display_csv.
      ELSE.
    *Display in ALV
        PERFORM display_alv.
      ENDIF.
    *&      Form  display_alv
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM display_alv .
      DATA: gr_alv TYPE REF TO cl_salv_table,
            gr_func TYPE REF TO cl_salv_functions,
            gr_columns TYPE REF TO cl_salv_columns_table,
            gr_column TYPE REF TO cl_salv_column_table,
            gr_error TYPE REF TO cx_salv_error.
      TRY.
          CALL METHOD cl_salv_table=>factory
            IMPORTING
              r_salv_table = gr_alv
            CHANGING
              t_table      = it_table.
        CATCH cx_salv_msg INTO gr_error.
      ENDTRY.
      gr_func = gr_alv->get_functions( ).
      gr_func->set_all( abap_true ).
      gr_alv->display( ).
    ENDFORM.                    " display_alv
    *&      Form  display_csv
    *       text
    *  -->  p1        text
    *  <--  p2        text
    FORM display_csv .
      DATA: w_filename TYPE string.
      CONCATENATE p_file temp_string INTO w_filename.
      CALL FUNCTION 'SAP_CONVERT_TO_CSV_FORMAT'
        EXPORTING
          i_field_seperator    = ';'
        TABLES
          i_tab_sap_data       = it_table
        CHANGING
          i_tab_converted_data = it_table_csv
        EXCEPTIONS
          conversion_failed    = 1
          OTHERS               = 2.
      IF sy-subrc <> 0.
        MESSAGE ID sy-msgid TYPE sy-msgty NUMBER sy-msgno
        WITH sy-msgv1 sy-msgv2 sy-msgv3 sy-msgv4.
      ENDIF.
      CALL FUNCTION 'GUI_DOWNLOAD'
        EXPORTING
          filename = w_filename
        TABLES
          data_tab = it_table_csv
        EXCEPTIONS
          OTHERS   = 1.
      PERFORM display_alv.
    ENDFORM.                    " display_csv

  • Select in CASE statement or in IF-THEN-ELSE

    I have been struggling for a week with a problem and still can't solve the way I want.
    Given four text fields in page : p1_name, p1_place_name, p1_place_number and p1_place_init_letter - where user types text and press 'Search' button to see the results.
    p1_name finds results in table EMPLOYEES
    p1_place_name, p1_place_number and p1_place_init_letter find results in table PLACES
    the two tables are linked by id_place field
    I would like reports to be shown depending on search results:
    - if p1_name exists and (p1_place_name and p1_place_number and p1_place_init_letter) exist AND EMPLOYEES.id_place = PLACES.id_place then a single report shows only employee row
    - if p1_name exists and (p1_place_name and p1_place_number and p1_place_init_letter) exist AND EMPLOYEES.id_place # PLACES.id_place then two reports showing 1) employees with name = :p1_name and 2) places with name, number and init_letter = :p1_.....
    - if p1_name not exists and (p1_place_name and p1_place_number and p1_place_init_letter) exist then a message with 'NO EMPLOYEE' and report shows only places where name, number and init_letter = :p1_.....
    - if p1_name exists and (p1_place_name and p1_place_number and p1_place_init_letter) not exist then report shows only employee row where name = :p1_name and message with 'NO PLACE'
    - if p1_name not exists and (p1_place_name and p1_place_number and p1_place_init_letter) not exist then messages 'NO EMPLOYEE' and 'NO PLACE'
    I do NOT know if it is possible, and if it is, then what do I have to use : IF - THEN - ELSE or CASE ?
    I tried to build HTML report region conditionally shown for each situation, but they do not work the way I want.
    Could you please help me ?
    Thank you in advance !

    Agree with Dan. Use a dedicated report region for a unique query. Use a rendering condition to determine if that reporting region must be rendered (i.e. whether or not that reporting query must be executed ).
    The alternative is creating a function that constructs the SQL query dynamically, based on the user supplied values for page items. Use the function as the source for the reporting region, instead of a SQL statement. (this is similar to creating a ref cursor for a client, minus the actual step to create the ref cursor - instead the source SQL for that ref cursor is returned).
    Also consider asking your Apex questions in the dedicated Apex forum on OTN.

  • Using if the else logic in regards to a select statement for a report

    Hi all,
    I've a question regarding if then else logic in Oracle.
    I'm developing a report application which contains 3 selectlists
    - ProductGroup - SubGroup - Manufacturer
    Each one containing several values. And are based on eachother, meaning if you select an item from the PG list, you only get the SG items regarding the PG item you've choosen before. The process logic should be as the following:
    When a user selects one item from for example the PG list, the query will be:
    select * from x where PG = :P_PG
    and the report displays all the items in the PG category selected
    The other two bindvariables would be null as the user didn't pick them
    If he then proceeds and selects one item from the SG list, the query would be:
    select * from x where PG = :P_PG and SG = :P_SG
    and the report displays all the items in the PG and SG category selected
    If he then proceeds and selects one item from the MA list, the query would be:
    select * from x where PG = :P_PG and SG = :P_SG and MA =:P_MA
    and the report displays all the items in the PG and SG and MA category selected
    Now, I've read some documentation about the decode function, but I can't figure it out, please help.
    Peter

    Okay, Chet, have set it up on htmldb, so you can see my problem, will go in high detail, it is not producing what I want. Example on htmldb:
    DEMO/test
    http://htmldb.oracle.com/pls/otn/f?p=33229:6
    Defenitions:
    3 LOV's, namely:
    - LOVPG - select distinct productgroep, productgroep pg from plijst
    - LOVSG - select distinct subgroep, subgroep sg from plijst where productgroep = :P6_LOVPG
    - LOVLE- select distinct leverancier, leverancier le from plijst where productgroep = :P6_LOVPG and subgroep = :P6_LOVSG
    3 Selectitems with submit, namely:
    - :P6_LOVPG
    - :P6_LOVSG
    - :P6_LOVLE
    Report region select statement:
    select * from plijst where (productgroep = :P6_LOVPG or :P6_LOVPG IS NULL) and (subgroep = :P6_LOVSG or :P6_LOVSG IS NULL) and (leverancier = :P6_LOVLE or :P6_LOVLE IS NULL)
    Branch to:
    Branche to page on submit after processing
    What it should do is:
    When you select an item from the first selectlist, productgroep, the report should show all rows containing the specified productgroep.
    When the user selects the next item in the subgroep selectlist, the report should show all rows containing the previously selected prodctgroup and the just selected subgroep.
    When the user selects the final item , the report should show all rows based on all three selected itemvalues, productgroep, subgroep, leverancier.
    The problem is that with this setup the report is only generated after the final selectlist choice of the user. But the user should see a report before that, going deeper into the structure. Hope, you see my problem?
    Sincerely,
    Pete

  • Usage of exists in if-then-else statements

    please correct the mistakes in this procedure regarding exists in the use of if then else statement .as i am new to oracle i am unable to do it.
    errors are statement ignored
    exists should be inside the statement;
    CREATE or replace FUNCTION CHECK_FG_Id
    p_LegacyDocumentId VARCHAR2,
    p_LegacyFGroupId VARCHAR2,
    p_TransmissionId INTEGER
    RETURN INTEGER as
    BEGIN
    IF EXISTS
    (Select FG.ControlNo from functionalgroup FG,document D
    WHERE FG.DocumentId=D.Id AND D.TransmissionId=p_TransmissionId
    AND FG.ControlNo=p_LegacyFGroupId AND D.ControlNo=p_LegacyDocumentId ) THEN
    Return 1;
    ELSE
    Return 0;
    END IF;
    end;

    Lots of different ways...One way is as follows:
    CREATE OR REPLACE FUNCTION check_fg_id (
    p_legacydocumentid VARCHAR2,
    p_legacyfgroupid VARCHAR2,
    p_transmissionid INTEGER) RETURN INTEGER AS
    vDoesItExist NUMBER;
    BEGIN
    SELECT COUNT (1)
    INTO vdoesitexist
    FROM functionalgroup fg,
    document d
    WHERE fg.documentid = d.ID
    AND d.transmissionid = p_transmissionid
    AND fg.controlno = p_legacyfgroupid
    AND d.controlno = p_legacydocumentid;
    IF vDoesItExist > 0 THEN
    RETURN 1;
    ELSE
    RETURN 0;
    END IF; /** vDoesItExist > 0 **/
    END check_fg_id;

  • If Then Else Statement in SAP R/3 BW

    Hi,
    Does anyone know how to create an If Then Else statement in BEX?
    Thanks,
    Mounika.

    Hi mounika,
    do this way
    If 'material number' > 0.
    rslt = 'enter into table'.
    else.
    rslt = 15.
    endif.
    A True condition always evaluates to 1, a False condition evaluates to 0.
    for more quieries in bw ..pls go through  the link
    http://sap.ittoolbox.com/groups/technical-functional/sap-bw
    pls reward if helps,
    regards.

  • Select statement in if/else condition

    Hi i need to write a select statement in the if condition in pl/sql how can i write this
    example :
    if field_name not in (select statement) then
    Is this type of if condition is possible in pl/sql?
    thanks in advance for help.

    Qwerty wrote:
    here pick a job example salesman for ename ward, now i want to compare this job that is "salesman" with all the jobs which are before it. that is clerk in line 1 and salesman in line 2Define "before it". There is no order in relational tables. Only ORDER BY means ordered sets. Therefore there is no before/after without ORDER BY. Assuming ORDER BY empno, job count of same job title before empno:
    select  ename,
            job,
            count(*) over(partition by job order by empno) - 1 same_job_count_before_empno
      from  emp
    ENAME      JOB       SAME_JOB_COUNT_BEFORE_EMPNO
    SCOTT      ANALYST                             0
    FORD       ANALYST                             1
    SMITH      CLERK                               0
    ADAMS      CLERK                               1
    JAMES      CLERK                               2
    MILLER     CLERK                               3
    JONES      MANAGER                             0
    BLAKE      MANAGER                             1
    CLARK      MANAGER                             2
    KING       PRESIDENT                           0
    ALLEN      SALESMAN                            0
    ENAME      JOB       SAME_JOB_COUNT_BEFORE_EMPNO
    WARD       SALESMAN                            1
    MARTIN     SALESMAN                            2
    TURNER     SALESMAN                            3
    14 rows selected.To find job count of same job title as Ward has before Ward (by empno):
    SELECT  same_job_count_before_empno
      FROM  (
             select  ename,
                     count(*) over(partition by job order by empno) - 1 same_job_count_before_empno
               from  emp
      WHERE ename = 'WARD'
    SAME_JOB_COUNT_BEFORE_EMPNO
                              1SY.

  • Java If/Then/Else Statement

    Hello,
    Just wondering if it is possible to call one java file from within another.
    I'm thining wiht an if.then/else statement similar to
    If x==true
    then run file1.java
    else run file2.java
    any examples of this, or if it is even possible would be appreciated.

    This is something like what I would do.
    public class FileRunner {
        public static void main(String [] args) {
            if ( args[0].equals("file1") {
                File1 file1 = new File1();
                file1.init() //method you define in File1 that runs everything that would've been in the File1's main method
            } else if (args[0].equals("file2") {
                File2 file2 = new File2();
                file2.init() //method you define in file2 that runs everything that would've been in the File2's main method
            } else {
                System.err.println("Invalid argument");
                System.exit(1);
    java.exe FileRunner.class file1
    java.exe FileRunner.class file2The other method is to start a new jvm from within java, but that gives you less control than this imo.

  • How to total 2 colums with an -If then else- statement each

    Hello,
    I have 2 colums A en B who generate data based on an “If then else” statement.
    Colum A
    <?xdofx:if (OMZET_YTD_VJ )!='' then ((OMZET_YTD_VJ) * (BM_YTD - BM_YTD_VJ)) div 100 else 0 end if?>
    Colum B
    <?xdofx:if (BM_YTD)!='' then ((BM_YTD) * (OMZET_YTD - OMZET_YTD_VJ)) div 100 else 0 end if?>
    Colum C needs to be the sum of both. Who can help me?
    Thanks a lot.

    Can you send me the RTF template and xml file to [email protected]? I can take a look and try to help.
    Thanks,
    Bipuser

  • Inserting a 'null' value in an IF THEN ELSE statement

    Greetings,
    I'm using Business Object webi XiR3
    I'd like to return a 'null' value in certain cases for an IF THEN ELSE statement.  Depending on if I format the field as a text or a number, I can return blanks ("") and zeros (0).  However, what I really need to do is leave the field / column formatted as a number and return a 'null' value.  You can see the variable below ... this will return a blank but the column is text.
    Suggestions?
    thanks.
    variable:
    =If([Comp Rate Mid] = 0 And( ([Market Rate 50th].085) - [Annual Total Targeted Comp] >=0) ; ([Market Rate 50th]0.85) - [Annual Total Targeted Comp]; If([Comp Rate Mid] <> 0 And( ([Comp Rate Mid] 0.85) - [Annual Total Targeted Comp] >=0) ; ([Comp Rate Mid]0.85) - [Annual Total Targeted Comp];""))

    I don't think this is possible using a formula, as formulas deal with content, and images can be placed in cells only as 'image fill', which is Format, rather than Content.
    Might be possible using an AppleScript, but I'm not the person to advise you on that.
    Regards,
    Barry

  • If statement in select statement alias

    I have the following select statement. It has the alias Survivors, Deaths and "All Cases". Is it posible to use :P_LANGUAGE variable to say that -- IF :P_LANGUAGE = FRENCH THEN alias are Survivants for survivors, Décès for Deaths, Tous_les_cas for All Cases. Please advise
    SELECT ALL T_NTR_MULTIBAR.CAT, T_NTR_MULTIBAR.NUM_CASES_LEFTBAR AS Survivors,
    T_NTR_MULTIBAR.NUM_CASES_MIDDLEBAR AS Deaths, T_NTR_MULTIBAR.NUM_CASES_RIGHTBAR AS "All Cases"
    FROM T_NTR_MULTIBAR
    WHERE INSTANCE_NUM = :P_INSTANCENUM
    order by ORDERS

    You may not be able to add this condition inside the SQL Statement. But you can add this condition outside the statement, if you're using PL/SQL...
    IF :p_language = french THEN
    SELECT ALL t_ntr_multibar.cat,
      t_ntr_multibar.num_cases_leftbar AS survivors,
      t_ntr_multibar.num_cases_middlebar AS deaths,
      t_ntr_multibar.num_cases_rightbar AS "All Cases"
    ELSE
    END IF;

  • Using if logic in the where clause of a select statement

    I have a select clause. And in the select clause there is a variable all_off_trt that can be 'Y' or 'N'.
    In the where clause I want to make it so that if a form variable is checked and all_off_trt is 'Y' then
    exclude it else if the form variable isn't checked then select it no matter what all_off_trt is.
    Is there any way to include either and if statement or a case statement within the where clause to acheive this? If not is there another way of doing it?
    Basically I am looking for a case statement like this
    case
    when all_off_trt = 'Y' and mail_para.code = 'Y' then false
    else true
    end
    Message was edited by:
    Tugnutt7

    Ok, so that really doesn't solve my problem. I have 3 different fields that I need to do that with. Each combining in a select statement to print an email list, as well as other thing limiting the where clause.
    This is currently what I have, tested and working 100%.
    cursor email_cur is
         select unique p.email,s.all_off_trt,s.all_deceased,s.no_enroll
    from participant p, trialcom t, ethics s
    where p.status='A'
    and p.surname=t.surname
    and p.initials=t.initials
    and s.trial_cd = t.tricom
    and s.centre = t.centre
    and p.email is not null
    and (t.centre in (select code from mail_parameters where user_name=user and mail_para='CENTRE')
    or 'XX' in (select code from mail_parameters where user_name=user and mail_para='CENTRE'))
    and (t.tricom in (select code from mail_parameters where user_name=user and mail_para='TRIAL')
    or 'XX' in (select code from mail_parameters where user_name=user and mail_para='TRIAL'))
    and (t.role in (select code from mail_parameters where user_name=user and mail_para='ROLE')
    or 'XX' in (select code from mail_parameters where user_name=user and mail_para='ROLE'))
    and (p.country in (select code from mail_parameters where user_name=user and mail_para='COUNTRY')
    or 'XX' in (select code from mail_parameters where user_name=user and mail_para='COUNTRY'))
    and (t.represent in (select code from mail_parameters where user_name=user and mail_para='REPRESENT')
    or 'XX' in (select code from mail_parameters where user_name=user and mail_para='REPRESENT'));
    This is in a program unit that runs when a button is clicked. At the end of that I need to add on the 3 case statements that help further narrow down the selection of emails to be printed. Then it prints the emails selected from this statement into a file. So it has to be done right in the select statement. The three table variables are the all_off_trt, all_deceased, and no_enroll. The form has 3 checkboxes. One for each, that when checked (giving the variable associated with the checkboxes a value of 'Y') excludes all emails that have a 'Y' in the coresponding table variable.

  • Problem in If-Then-Else formula in report

    Hello guys!
    I use an If-Then-Else statement in a Calculated Key Figure (Cf. <a href="http://help.sap.com/saphelp_nw04s/helpdata/en/23/17f13a2f160f28e10000000a114084/content.htm">Conditional Calculations</a> ) and it works great with basic calculations.
    I have a query (done in BI 7.0) where I display, for each calendar months (via 0CALMONTH), the usage (stored in a normal key figure in hours) of several products.
    I need to take into account only the products that have been used for at least 60% of the time of the highest product for each month. I a single product, for a month, has been used less than 60% of the highest one, it should be considered as not being used at all (so the calculated usage would be = 0), otherwise, its usage is counted as normal.
    In order to achieve this, I thought I would display the normal usage (the regular key figure) in column A, a calculated key figure that determines the MAXimum usage for each month in column B (which should be the same for all products) and another calculated key figure that displays the result of the If-Then-Else statement in column C.
    In rows, I have 0CALMONTH and the products.
    HOWEVER, when I do this, the result is incorrect. This is probably because to determine the MAX usage, I use a local calculation option, which displays the correct maximum usage on each row but it's not correct when used somewhere else.
    <b>MY QUESTION IS: HOW can I display the maximum usage for a month on all rows without using the calculation option (and therefore would be correctly used by the If-Then-Else statement. I tried an aggregation exception but it doesn't really work (it works only on the total, but I need to do the calculation on each individual row).</b>
    <u><b>Any useful comment will be greatly appreciated </b></u>
    Thanks in advance!

    Hi Francal ,
    Have you tried it . The constant selection will work if you have defined the calculated key figure correctly i.e. Aggreagtiomn "Max" with "product" as ref characteristic. Then you have to use this calculated key figure in your query , restrict it by "product" and make it a constant selection.
    The calculated key figure it self  will bring the highest usage for Month + product + ( any other characteristic you have in query ) but this will only apply to result . If you use constant seelction on top of it it will make sure that you see same value for all product for a particular month( and other characteristic combinations if you have ).
    I have built similar queries and it works . By the way which versions of backend and frontend you have ??
    Regards
    Sanjay

Maybe you are looking for

  • Why did Apple remove flag icon from iPhoto '11?

    I just updated to iPhoto '11 and there are a few interesting changes.  One is that Apple removed the "flag" icon from the app.  I wish they hadn't done that because I use that a lot and don't want to have to go to the dropdown menu to flag a photo. 

  • Price determination for BOM

    Hi guys, how are you. One scenario : I am using the header level BOM(printer) Alternative 1 : 2tray                 :  1no hard disk(20GB) : 1no Duplex kit          :  1no Alternative 2 : Hard disk(20GB)  : 1no Stand                 :  1no Duplex kit

  • HIDING COLUMNS ISSUE

    Hi Gurus, Experts, Friends, i need help from you in this scenario. we have a "4 dayprocess" where it will be done every month and by this we get ESTIMATE values for the very next month what we run up to. The values what we actually get in the particu

  • Co Product & By Product Scenario in CO

    Dear CO Experts, I have scenario regarding Co Product and By Product in my client place. May I know that what is the Co Product and By Product concept in Controlling module and how valuation and standard prices happened. Please let me know what are t

  • Problem after updating to ios 6.1

    Hi, I updated my iPhone 4 to ios 6.1 and lost all my contacts, text messages and most importantly my photos. I did the backup just before upgrading and now when I restore it back, it turns out to be like a new phone.How to get back photos and text me