473,473 Members | 1,951 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How to perform a query for a string which contains an "&"?

I am searching a table column for a value 'Policy & Procedures'
The "&" causes the query to fail.
Nov 19 '10 #1
2 9291
yarbrough40
320 Contributor
use brackets [Policy & Procedures]
Nov 22 '10 #2
vijay2082
112 New Member
Hi,

Use escape construct in your query.

C:\backup>db2 "insert into db2admin.mytable values('kunal & vijay')"
DB20000I The SQL command completed successfully.

C:\backup>db2 select * from db2admin.mytable

NAME
------------------------------
ajay
shubhangi
kunal
SHUBHANGI
kunal & vijay

5 record(s) selected.

> below query will return an error as expected

C:\backup>db2 select * from db2admin.mytable where name like '%&%'
SQL0010N The string constant beginning with "'%" does not have an ending
string delimiter. SQLSTATE=42603
'%'' is not recognized as an internal or external command,
operable program or batch file.

> Use escape character to make your search

C:\backup>db2 "select * from db2admin.mytable where name like '%&&%' escape '&' "

NAME
------------------------------
kunal & vijay

1 record(s) selected.


C:\backup>db2 "insert into db2admin.mytable values('kunal _ vijay')"
DB20000I The SQL command completed successfully.

C:\backup>db2 select * from db2admin.mytable

NAME
------------------------------
ajay
shubhangi
kunal
SHUBHANGI
kunal & vijay
kunal _ vijay

6 record(s) selected.

C:\backup>db2 "select * from db2admin.mytable where name like '%__%' escape '_' "

NAME
------------------------------
kunal _ vijay

1 record(s) selected.


C:\backup>db2 "insert into db2admin.mytable values('kunal / vijay')"
DB20000I The SQL command completed successfully.

C:\backup>db2 "select * from db2admin.mytable where name like '%//%' escape '/' "

NAME
------------------------------
kunal / vijay

1 record(s) selected.

Cheers, Vijay
Nov 25 '10 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: James Thurley | last post by:
I'm creating an XmlDocument manually, adding content using the Xml classes such as XmlElement and XmlText, and I then write it out as as "text/xml" to the HttpResponse.Output TextWriter object...
4
by: Luklrc | last post by:
Hi, I'm having to create a querysting with javascript. My problem is that javscript turns the "&" characher into "&" when it gets used as a querystring in the url EG: ...
4
by: sushi | last post by:
Hello, I want to make an http post request to a site. I want to pass a paramaeter having xml such as report=<abc>abc</abc> to it. When I try to do this, is gives exception. And If send...
0
by: Grzegorz Kaczor | last post by:
Hello, I have an ASP.NET application in my website in virtual folder A. This folder contains the application itself. I also have a data virtual directory B which contains data that can be seen...
1
by: pangel83 | last post by:
I've been trying for days to write a piece of VB.NET code that will read from winamp's memory space the paths of the files from the current winamp playlist. The GETPLAYLISTFILE command of the...
4
by: moondaddy | last post by:
I have a situation where I will collect text from a textbox and pass that text as one of the parameters in another pages query string. the problem is that if the user types in a '&' as part of the...
0
by: sajjad.mussani | last post by:
Hi, I have a ReportViewer control on my aspx page which is creating a report when a user clicks on some button. The problem is that it cannot find the Scripts.ReportViewer.js file as the...
4
by: mark4asp | last post by:
I have an element, report which contains tags which have been transformed. E.g. <pis &lt;p&gt <myXml> <report>This text has html tags in it.&lt;p&gt which but <has been changed to &lt;&gt</report>...
11
by: prisesh26 | last post by:
hi, iam passing a name "sun & moon" in my query string as a parameter. but when i receive it through request.getParameter iam getting only sun. rest are getting ignored due to & symbol. how...
3
by: Roger F | last post by:
Help Please When I insert code into my database ie. This & That I see it is the same in the data base but when I go to view it, it as changed into. This &amp; That What is happening, rather a...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.