Results 1 to 3 of 3
  1. #1
    Join Date
    Jan 2003
    Posts
    1,605

    Unanswered: When "where col1 like %a%" in Window batch file, %a% is recognized as system variable

    Hi,
    On "DB2 WSE v8.2 fp9 on Windows XP SP2" I would like to execute Windows batch file with SQL statements. My batch file looks like this:

    Code:
    db2 create table db2admin.tab1 (col1 char(10))
    db2 insert into db2admin.tab1 values ('abc'),('bac'),('caa')
    db2 select * from db2admin.tab1
    Select returns the following result:
    Code:
    COL1
    ----------
    abc
    bac
    caa
    So far so good, but deleting all rows with like command (as follows)...:
    Code:
    db2 delete from db2admin.tab1 where col1 like '%a%'
    ... returs following warning: "SQL0100W No row was found for FETCH, UPDATE or DELETE; or the result of a
    query is an empty table. SQLSTATE=02000".

    The above problem appears because Windows batch file recognizes %a% as system variable. Because system variable %a% does not exist the value of %a% is empty string. So SQL looks like:
    Code:
    where col1 like ''
    which is obvious no rows are deleted.

    So how to write "... where col1 like '%a%' " in batch file?

    Thanks a lot,
    Grofaty
    Last edited by grofaty; 12-19-06 at 10:41.

  2. #2
    Join Date
    Jun 2003
    Location
    Toronto, Canada
    Posts
    5,516
    Provided Answers: 1
    Replace "%" with "%%".
    ---
    "It does not work" is not a valid problem statement.

  3. #3
    Join Date
    Jan 2003
    Posts
    1,605
    Hi,
    thank you very very very very much.
    Grofaty

Posting Permissions

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