If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > DB2 > When "where col1 like %a%" in Window batch file, %a% is recognized as system variable

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 12-19-06, 09:36
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
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 09:41.
Reply With Quote
  #2 (permalink)  
Old 12-19-06, 10:06
n_i n_i is offline
:-)
 
Join Date: Jun 2003
Location: Toronto, Canada
Posts: 4,449
Replace "%" with "%%".
Reply With Quote
  #3 (permalink)  
Old 12-19-06, 12:52
grofaty grofaty is offline
Registered User
 
Join Date: Jan 2003
Posts: 1,570
Hi,
thank you very very very very much.
Grofaty
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On