Results 1 to 3 of 3
  1. #1
    Join Date
    Feb 2003
    Posts
    20

    Unanswered: Using Multiple LIKE parameters in SELECT

    I am using DB2 UDB V8.1 with FixPack 5. I have a table test1 with one column col1 and I have the following data in the table:

    COL1
    ----------
    C_TEST1
    COMMON
    C_TEST2
    COX CABLE
    C__TEST1
    C__OMMON
    C__TEST2
    COX_CABLE
    R__TEST1
    R__OMMON
    R__TEST2
    ROX_CABLE

    12 record(s) selected.

    I want to select all the records which are like C_ and R_.

    I am issuing the following command to get the records which are like C_ and R_

    1) db2 "select * from test1 where col1 like 'C\_%' or col1 like 'R\_%' ESCAPE '\'"

    COL1
    ----------
    R__TEST1
    R__OMMON
    R__TEST2

    3 record(s) selected.

    When I issue the command

    2) db2 "select * from test1 where col1 like 'R\_%' or col1 like 'C\_%' ESCAPE '\'"

    I am getting the following result:

    COL1
    ----------
    C_TEST1
    C_TEST2
    C__TEST1
    C__OMMON
    C__TEST2

    5 record(s) selected.

    I am expecting my result set to be UNION of 1) and 2).

    Can anybody tell me if I am doing anything wrong or there is a problem with UDB?

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    ESCAPE '\' must be a part of each LIKE predicate:
    Code:
    select * from test1 where col1 like 'R\_%' ESCAPE '\' or col1 like 'C\_%' ESCAPE '\'

  3. #3
    Join Date
    Aug 2003
    Posts
    106
    You can also try

    SELECT * FROM TEST1 WHERE SUBSTR(COL1,1,2) = 'C_' OR SUBSTR(COL1,1,2) = 'R_'

    You are the creator of your own destiny!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •