HELP: WHERE Clause based on value of the column

I am selecting from a table as follows and want to have a where condition that is dependent of the value of the column, type of the current row.
CREATE TABLE tbl (INT id, VARCHAR type, VARCHAR comment)
I have 3 different values for the type column, EMPLOYEE, CUSTOMER, SUPPLIER. What I want is to have a where clause in my select that is based on the value of type.
I tried the following but was not successful..
SELECT * from tbl
CASE
WHEN type = 'EMPLOYEE' THEN
WHERE comment LIKE '%employee%'
WHEN type = 'CUSTOMER' THEN
WHERE comment LIKE '%customer%'
WHEN type = 'SUPPLIER' THEN
WHERE comment LIKE '%supplier%'
END
I am not proficient with stored procedures so if you could please tell me how to do it with straight query, I would greatly appreciated it..
Thank you,

Or maybe this:
SELECT *
  FROM tbl
WHERE "COMMENT" LIKE
          CASE TYPE
             WHEN 'EMPLOYEE'
                THEN '%employee%'
             WHEN 'CUSTOMER'
                THEN '%customer%'
             WHEN 'SUPPLIER'
                THEN '%supplier%'
          END

Similar Messages

  • Where clause with null values

    I need to have a where clause but either/both of the two attributes compared could be null. How can I make this work, atm it just returns no records even though rows do exist.
    Thanks

    Andrew,
    I think you didn't read correctly what I wrote. I said:
    "Even if a column is unique you still can have several nulls in it"
    So I didnt speak about the case where you have severeal columns in a unique constraint but only ONE.
    SQL> CREATE TABLE tab1 (col1 number);
    Table created.
    SQL> ALTER table tab1 add constraint tab1_col1_uk unique (col1);
    Table altered.
    SQL> INSERT INTO tab1 VALUES (1);
    1 row created.
    SQL> INSERT INTO tab1 VALUES (2);
    1 row created.
    SQL> INSERT INTO tab1 VALUES (2);
    INSERT INTO tab1
    ERROR at line 1:
    ORA-00001: unique constraint (MUELLERMAU.TAB1_COL1_UK) violated
    SQL> INSERT INTO tab1 VALUES (NULL);
    1 row created.
    SQL> INSERT INTO tab1 VALUES (NULL);
    1 row created.
    And even if you have a unique constraint over several columns you can still have more than on records containing only nulls in all fields related to that unique contraint.
    SQL> CREATE TABLE nn (col1 number, col2 varchar2(3));
    Table created.
    SQL> ALTER TABLE nn ADD CONSTRAINT nn_uk UNIQUE (col1, col2);
    Table altered.
    SQL> INSERT INTO nn VALUES (NULL,NULL);
    1 row created.
    SQL> INSERT INTO nn VALUES (NULL,NULL);
    1 row created.
    Regards
    Maurice

  • Dynamic where clause for MULTIPLE values

    In the following of dynamic where clause?
    i have some somewhat different problem.
    Is a dynamic where clause for multiple values possible?
    If the inputvariable varCode1,varCode2,varCode3,varCode4 are 0 then show all id's otherwise filter the resultset on var1 and/or var2,and/or var3,and/or var4.
    Example table:
    create table t
    (d int,var int);
    insert into t values (1 ,1 );
    insert into t values (2 ,1 );
    insert into t values (3 ,2 );
    insert into t values (4 ,3 );
    insert into t values (5 ,4 );
    insert into t values (6 ,4 );
    insert into t values (7 ,4 );
    insert into t values (8 ,4 );
    insert into t values (9 ,5 );
    insert into t values (10, 6);
    insert into t values (11, 6);
    So what i want to change the where clause upon the value of the varCodes. If var1 and var are not 0 a "AND" should be used otherwise an "OR"
    select id
    from tst
    where var = DECODE( :varCode1, 0, var, :varCode1)
    or/and(?) DECODE( :varCode2, 0, var, :varCode2)
    or DECODE( :varCode3, 0, var, :varCode3)
    or DECODE( :varCode4, 0, var, :varCode4)

    Please turn off your Caps Lock
    and try this link
    Dynamic WHERE clause

  • I have MAC OSX 10.5.8 and need to install adobe illustrator. I checked the compatibility and found that CS5 will work.Can any one help where i can find it. The trail version is fine with me.

    I have MAC OSX 10.5.8 and need to install adobe illustrator. I checked the compatibility and found that CS5 will work.Can any one help where i can find it. The trail version is fine with me as i just have to use it for couple of days till i get my mac book back from service. Can any one help me on this.

    You are welcome, ameronweb.
    To elaborate a bit, you may come across offers of a new/unopened/unregistered version, which is the simplest case (you would need a guarantee). Other cases require much detailed information (and a guarantee).
    If upgrading to 10.6.8 or higher is an option, you could use CS6.

  • Dynamically display title based on value selected in column selector

    Hi All,
    Can it be possible to show the report title dynamically based on value selected in column selector . suppose i have two column status and region . When i will select status in the column selector the title of the report will show " Status Summary" when i will select region then the title will change to "Region Summary". Please help me...

    Hi,
    create dashboard prompt with column selector functionality like following way
    write the following query in your dashboard prompt sql results
    select region name from subject area name
    Union all
    select sub_region name from subject area name
    like this and put one presentation variable for this dashboard prompt like var1
    in your report write formula in your column like this *case when @{var1)='region column' then 'Region Summary' else ' ' end*
    and refer this column in narrative view like @1 then narrative act like a title view.
    Hope this helps you
    Regards
    Naresh                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • ColumnChart color depending on the value of the column

    Hi,
    I'va been trying for 2 days to change the colors of columnseries in a columnchart and it is actually awful. I've tried to do it inline without custom itemRenderer but I quickly understood that it is impossible. I then looked on the internet, and found that it was maybe possible by creating a custom itemRenderer class, extending ProgrammticSkin and implementing IdataRenderer.
    I have tried but am not at all able to retrieve the value of the column inside the itemRenderer. Even more, the so called _chartItem is always null and never never carries anything from anyparent.
    I'm a bit exhausted of trying and getting this value, so if you have some idea, i'll be very grateful.
    Here is the code for my itemRenderer class:
    import flash.display.Graphics;
        import flash.geom.Rectangle;
        import mx.charts.ChartItem;
        import mx.charts.chartClasses.GraphicsUtilities;
        import mx.charts.series.items.ColumnSeriesItem;
        import mx.controls.Alert;
        import mx.core.IDataRenderer;
        import mx.graphics.IFill;
        import mx.graphics.IStroke;
        import mx.skins.ProgrammaticSkin;
        public class ColorRenderer extends ProgrammaticSkin implements IDataRenderer
            public function ColorRenderer():void
                super();
            private var _chartItem:ChartItem;
            public function get data():Object
                return _chartItem;
            public function set data(value:Object):void {
                _chartItem = value as ColumnSeriesItem;
                invalidateDisplayList();
            private static const fills:Array = [0xFF0000,0x00FF00,0x0000FF,
                0x00FFFF,0xFF00FF,0xFFFF00,
                0xAAFFAA,0xFFAAAA,0xAAAAFF];
            override protected function
                updateDisplayList(unscaledWidth:Number,unscaledHeight:Number):void {
                super.updateDisplayList(unscaledWidth, unscaledHeight);
                var g:Graphics = graphics;
                g.clear(); 
                g.beginFill(fills[(_chartItem == null)? 0:_chartItem.element.y]);
                Alert.show(_chartItem.index.toString());
                g.drawRect(0, 0, unscaledWidth, unscaledHeight);
                g.endFill();
        } // Close class.
    } // Close package.
    Thank you

    It worked, thanks
    Date: Wed, 21 Apr 2010 09:03:14 -0600
    From: [email protected]
    To: [email protected]
    Subject: Flex ColumnChart color depending on the value of the column
    Have you looked at doing per-item fills?
    http://help.adobe.com/en_US/Flex/4.0/UsingSDK/WS2db454920e96a9e51e63e3d11c0bf69084-7c3f.ht ml
    This feature lets you define a function that customizes chart item fills based on their values.
    >

  • Adding more Values to the Column Link in Apex

    Hi,
    Is there any possibility of adding extra or more values to the column link in Apex. I already have 3 Column Name and Values linked to a different report.
    Eg:-
    Column Link:
    Link Text : #COUNT#
    Name       Value
    DATE #DATE#
    PRICE #PRICE#
    COST #COST#
    I want to add one more Name like 'ID' and corresponding and Value #ID#.
    Please Help...
    Thanks in Advance..
    Edited by: user13561710 on Jan 10, 2011 9:20 AM
    Edited by: user13561710 on Jan 10, 2011 12:34 PM

    Thanks Varad,
    But it didn't worked, The page has option to link only 3 values.
    My Target is 'Page in this Application" not a URL.
    I used your format and if you apply changes and come back the whole thing is dissappeared and even the link to page in application is inactive.
    Is there any other way???
    Thanks
    Edited by: user13561710 on Jan 10, 2011 10:49 AM
    Edited by: user13561710 on Jan 10, 2011 12:35 PM

  • How can can i subtract the value of the column in each row ?

    I want to subtract  the value  of the column in each row if the row is not enough then continue to next row.
    For example 
    ID             QTY
    A               20
    B               40       
    C               60
    I want to update this table by subtract  the value  of the column (QTY) out 70 so the result i want will be 
    ID              QTY
    A                20 - 70 = -50 -->  0 this row will be updated to 0 and 50 will continue to next row   
    B                40 - 50  = -10 -->  0   this row will be updated to 0 and 10 will continue to next row
    C                60 - 10  = 50  -->  Stop loop
    How can i write the sql query for this operation , Thanks

    Please post DDL, so that people do not have to guess what the keys, constraints, Declarative Referential Integrity, data types, etc. in your schema are. Learn how to follow ISO-11179 data element naming conventions and formatting rules. You have no idea,
    do you? Temporal data should use ISO-8601 formats. Code should be in Standard SQL as much as possible and not local dialect. 
    This is minimal polite behavior on SQL forums. What did you try on your own before posting? I will bet that you did nothing! You expect other people to do your job or homework for you. 
    >> I want to subtract the value of the column in each row if the row is not enough then continue to next row. <<
    This makes no sense. Rows have no ordering; that is a spreadsheet. There is no such thing as a generic “id” in RDBMS. And an identifier is not a sequence which would have an ordering. 
    CREATE TABLE Foobar
    (something_seq INTEGER NOT NULL PRIMARY KEY,
     onhand_qty INTEGER NOT NULL);
    Learn how to use the SUM()OVER() and LAG() aggregate functions, post what you tried for yourself and then we will help you. 
    --CELKO-- Books in Celko Series for Morgan-Kaufmann Publishing: Analytics and OLAP in SQL / Data and Databases: Concepts in Practice Data / Measurements and Standards in SQL SQL for Smarties / SQL Programming Style / SQL Puzzles and Answers / Thinking
    in Sets / Trees and Hierarchies in SQL

  • How to show the VALUE as the Column Header using SQL query?

    Hi
    I have a requirement to show the picked value as the column header using SQL query.
    Example:
    ======
    SELECT EMPNO FROM EMP
    WHERE EMPNO=7934;
    Result Should be:
    7934
    7934

    I have a requirement to show the picked value as the column header using SQL query.In sql*plus you can do
    SQL> set verify on
    SQL> def e =  7934
    old: SELECT empno "&&e"  FROM emp  WHERE empno = &&e
    new: SELECT empno "7934"  FROM emp  WHERE empno = 7934
    SQL> SELECT empno "7934"  FROM emp  WHERE empno = 7934
          7934
          7934
    1 row selected.

  • Format the total value in the column of the graph table

    Hello all,
    I have a graph table and I need to format the total value in the column of the table.
    I am trying to find my table bean with the code below but it's not working in the processRequest. Is there anything else that should be done?
    // Get the graph
    OAGraphTableBean graphBean = (OAGraphTableBean)webBean.findChildRecursive("MyGraph");
    // Get the table
    OATableBean tblBean = (OATableBean)graphBean.findChildRecursive("MyTable");
    The tblBean is null in the processRequest. In the processFormRequest the tblBean is not null.
    Thanks and Regards,
    Andrea

    Hi,
    The code OAGraphTableBean graphBean = (OAGraphTableBean)webBean.findChildRecursive("MyTable"); does not work because in this case I am getting the table but casting to a graph.
    The MyTable bean is a child of MyGraph.
    When creating a graph bean we have the option to create a table as a child (select your graphTable region in the Structure pane, and choose New > tabularFormat - to create the table).
    The table bean child I can get just in the processFormRequest, but the graph I can get in both processRequest and processFormRequest.
    I need to get the table bean in the processRequest to format the total value column.
    Do you know if is there anything else that should be done to format the total column?
    Thanks and Regards,
    Andrea

  • How to get warning by using the previous value of the column and new value

    Hi all,
    Suppose the column A has the true and when I click on button which also sets the value of the column as true I should dispaly warning that column a is already true.How can I achieve this.How to store the original value of the column and then check wirth the new value.
    Thanks in advance.

    You dont have to store the value anywhere
    You can do this from setMethod of EOImpl.java
    eg:
    void setAttributeXXX(String Value)
    // value contains new value
    // getAttributeXXX() contains oldValue
    if (value.equals(getAttributeXXX()))
    // Verify value is > 0 if (value.compareTo(0) <= 0)
    throw new OAAttrValException(OAException.TYP_ENTITY_OBJECT, // indicates EO source
    getEntityDef().getFullName(), // entity name
    getPrimaryKey(), // entity primary key
    "AttributeXXX", // attribute Name
    value, // bad attribute value
    "AK", // nessage application short name
    "FWK_TBX_T_EMP_SALARY_REQUIRED"); // message name
    setAttributeInternal(AttributeXXX, value);
    --Prasanna                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • Replaace values in the columns reverse direction

    Oracle 11.2.0.1
    Windows
    create table test
    code varchar2(2),
    col1 varchar2(2),
    col2 varchar2(2),
    col3 varchar2(2),
    col4 varchar2(2),
    col5 varchar2(2),
    col6 varchar2(2)
    insert into test values ('01','K','P','O','R',null,null);
    insert into test values ('02','I','S','L',null,null,null);
    insert into test values ('03','P',null,null,null,null,null);
    insert into test values ('04','K','N',null,null,null,null);
    insert into test values ('05','K','N','Z','G','H','T');
    SQL> select * from test;
    CO CO CO CO CO CO CO
    01 K  P  O  R
    02 I  S  L
    03 P
    04 K  N
    05 K  N  Z  G  H  T
    Required Output :  (Reverse Values in the columns)
    CO CO CO CO CO CO CO
    01 R  O  P  K
    02 L  S  I
    03 P
    04 N  K
    05 T  H  G  Z  N  K
    Thanks.

    with
    test as
    (select '01' code,'K' col1,'P' col2,'O' col3,'R' col4,null col5,null col6 from dual union all
    select '02','I','S','L',null,null,null from dual union all
    select '03','P',null,null,null,null,null from dual union all
    select '04','K','N',null,null,null,null from dual union all
    select '05','K','N','Z','G','H','T' from dual
    select code,
           substr(cols,instr(cols,'|',-1,2) + 1,instr(cols,'|',-1,1) - instr(cols,'|',-1,2) - 1) col1,
           substr(cols,instr(cols,'|',-1,3) + 1,instr(cols,'|',-1,2) - instr(cols,'|',-1,3) - 1) col2,
           substr(cols,instr(cols,'|',-1,4) + 1,instr(cols,'|',-1,3) - instr(cols,'|',-1,4) - 1) col3,
           substr(cols,instr(cols,'|',-1,5) + 1,instr(cols,'|',-1,4) - instr(cols,'|',-1,5) - 1) col4,
           substr(cols,instr(cols,'|',-1,6) + 1,instr(cols,'|',-1,5) - instr(cols,'|',-1,6) - 1) col5,
           substr(cols,instr(cols,'|',-1,7) + 1,instr(cols,'|',-1,6) - instr(cols,'|',-1,7) - 1) col6
      from (select code,rtrim('|'||col1||'|'||col2||'|'||col3||'|'||col4||'|'||col5||'|'||col6,'|')||'|' cols
              from test
    CODE
    COL1
    COL2
    COL3
    COL4
    COL5
    COL6
    01
    R
    O
    P
    K
    02
    L
    S
    I
    03
    P
    04
    N
    K
    05
    T
    H
    G
    Z
    N
    K
    Regards
    Etbin

  • Sorting is not working in infragistics when empty value in the column

    Hi ,
    i am using <ig:gridView> in my application. i have many columns in the grid view(ig means third party infragistics component). But in my case sorting(sortBy attribute in ig:column) is not properly working when the empty values in the column(DATA_ROW.source). This is a severity bug in my application. I have two days to deploy our project. I already hosted my bug report to the infragistics website. Please reply ASAP.
    <ig:column style="border:1px" sortBy="source">
    <f:facet name="header">
    <h:outputText style="color:#245B89;text-decoration:underline" value="Source System " title="Click to sort" />
    </f:facet>
    <h:outputText value="#{DATA_ROW.source}" />
    </ig:column>

    Hi,
    You can refer this post-
    https://social.technet.microsoft.com/Forums/office/en-US/b748bb03-4881-4aa5-9c87-bd4558b9201c/unable-to-sort-task-lists-by-assigned-to-column?forum=sharepointadminprevious
    Thanks,
    Danny
    Please remember to Mark as Answer if it works or vote of it is helpful

  • How to set the where clause of a value set on the basis of a form field

    I am using a DFF(Descriptive FlexField), which needs to display the value of a certain column(say columnA) on the basis of the value of another column(say columnB).
    So i have created a value set which points to the table which has both these columns, and the DFF uses this value set. However, the problem is that I have not put any where clause in the value set, because of which i cannot handle the exact fetch returns more than one rows error.
    The query has to be as follows:
    select ColumnA from tbl where ColumnB = [ a form value ];
    What I want to know is how can i get the value of a certain field of a certain block of the form in the above query.
    Edited by: 981615 on Jan 14, 2013 12:48 AM
    Edited by: 981615 on Jan 14, 2013 12:48 AM

    Just have a look over these two statements if it solves your problem
    one time where clause
    Set_Block_Property('BLOCK_NAME',ONETIME_WHERE,your form item);
    dynamic where clause
    set_block_property('BLOCK_NAME'default_where, your form itme)
    you can where clause at run time from any procedure or some triggers

  • Dynamic where clause based on Page Items

    I need an example of how to build a where clause with values from page items.
    I want to do something like the following but do not know the syntax:
    sql_string := ' where lab.ceventno is not null and lab.cts_no_show is null ';
    if :P1_RECID is not null then
    sql_string := sql_string || ' and lab.recid = ' || :P1_RECID;
    end if;
    if :P1_CAS_NO is not null then
    if :P1_CAS_TYPE = 1 then
    sql_string := ' and upper(lab.cas_no) = ' || :P1_CAS_NO;
    elsif :P1_CAS_TYPE = 2 then
    sql_string := ' and lab.ceventno in (Select ceventno from msds_ing where cas_no = ' || :P1_CAS_NO;
    end if;
    end if;
    :P2_WHERE := sql_string;
    I put this in a process that I want to pass to Page 2 when search button is pushed. I'm not sure what I'm doing wrong, but this doesn't seem to work.
    When I print out :P2_WHERE, I only get the first line
    'where lab.ceventno is not null and lab.cts_no_show is null '
    Any help would be much appreciaed
    Thanks
    Pam

    Pam - We need more details about exactly what you are doing, e.g., how are you going to dynamically execute that SQL, what items are on page 1 that will be submitted (all search criteria), what happens on page 2, etc.
    But here are a few points:
    1. when building a query for dynamic execution, put the bind variables like ":P1_RECID" into the generated SQL, e.g., do this:
      sql_string := 'select ename from emp where empno = :P1_EMPNO';
    not
       sql_string:= 'select ename from emp where empno ='||:P1_EMPNO;They may appear to give you the same results but the first introduces non-reusable SQL into the shared pool (this is bad).
    2. When code runs that references user-entered item values on the current page, like "if :P1_CAS_NO is not null", you have to make sure those items have been submitted (as with a page-submitting button) before you reference them. So if the user enters search criteria into form fields, then submits the page, then you reference those items in the SQL-building process, you'll be okay.
    3. Watch for errors like your line: "sql_string := ' and upper(lab.cas_no) = ' || :P1_CAS_NO;" which you may have intended to be "sql_string := sql_string||' and upper(lab.cas_no) = ' || :P1_CAS_NO;".
    Scott

Maybe you are looking for

  • Downloading from alv to excel file

    hai    while downloading from alv grid to excel  file   i am not getting values properly. i have taken 110 fields. i am not getting prper way. can u plz tel me way....

  • Date wise Valid Customers

    Hi Experts, I have a customer master data object with move in date and move out date as attributes. Now I want a report for number of customers valid for each day of a specified user entry date range. Let say I have date in the object like below. cid

  • Poor iasconsole perf; emagent using too much cpu; and errors in em*.logs

    Recently the emagent which runs with the iasconsole on our AppServer Mid Tier (10.1.2.0.2 AS and 10.1.0.4.2 emagent) has been using a ridiculous amount of CPU (28% of 8 Dual Core USIV+). The emagent for the INF Tier and for OEM Grid Control never eve

  • Problems with embedded font on spark RichText control

    « Hide I have an embedded font that appears correctly when used with Halo components, but when associated with the spark RichText component, it is not recognized. The embedded font is defined in css file, my css file @namespace s "library://ns.adobe.

  • Forms displaying arabic in Devsuite10gR2 but not in OAS10gR2?

    Friends, i have installed oracle developer suite 10g in windows xp sp2. In the default.env i have added the below line at the bottom NLS_LANG=AMERICAN_AMERICA.AR8MSWIN1256in the formsweb.cfg the last contents are. [ncc] form=faccn101.fmx WebUtilArchi