473,800 Members | 2,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Handling quotation marks and apostrophes

I've got a set of emails in a table, where sometimes they've failed to
input the @ properly.

Eg james.foreman'a bcmail.co.uk

How do I write a replace to deal with that?

Also, I've got a set of names in a table, all in lower case. I can
easily capitalise the first letter of each name, but if it's somebody
like O'Brien, I'd like to get that right too (so need to be able to
identify letters after a ' )

Thanks

James
Nov 12 '05 #1
3 9834
I'm not completely clear on what your question is: it sounds as if you are
concerned only with correcting the bad data and not with how it got there in
the first place. Frankly, I think you'll need to deal with both to fully
resolve the problem; there's no point in fixing the existing bad data
manually if the input procedures continue to allow bad data to be created in
your tables. Unfortunately, you haven't said anything about how you are
doing the input so this reply is going to get a bit wordy ;-)

There are many different techniques used for both inputting and correcting
data. In the case of very small amounts of rows, say a few dozen, you might
simply create the data using INSERT statements that you issue from the
command line or, more likely, write in a script and execute via db2 -tvf
<filename>. In both of those cases, you handle apostrophes by doubling them,
e.g. insert into table1 (id, name, salary) values(1, 'O''Brien', 50000).

For larger volumes of data, you will often use the IMPORT or LOAD command
to, in effect, copy the data from a flat file into DB2. The IMPORT and LOAD
commands have a MODIFIED BY clause that takes a number of arguments that
affect the behaviour of the command. For example, for ASCII files that are
being imported, the 'chardel' modifier can use the character of your choice
as the string delimiter; as long as you choose something other than an
apostrophe, apostrophes in a name like O'Brien should be handled properly.

If you are writing your own programs to load your data, I would suggest
using parameter markers in your insert statements; they will handle the
apostrophes for you, very cleanly in my experience. For instance, in a Java
program, something like this would work quite well and wouldn't have any
problems with names containing apostrophes:

----------------------------------------------------------------------------
---------------------------------
String insertSQL =

"insert into personnel " +

"(id, name, salary) " +

"values(?, ?, ?)";

PreparedStateme nt pstmt02 = null;

try {

pstmt02 = conn01.prepareS tatement(insert SQL);

}

catch (SQLException sql_excp) { //error handling omitted }

int numRowsInserted = 0;

try {

pstmt02.setInt( 1, 1);

pstmt02.setStri ng(2, "O'Brien");

pstmt02.setBigD ecimal(3, 50000.00);

numRowsUpdated = pstmt02.execute Update();

}

catch (SQLException sql_excp) { //error handling omitted }

----------------------------------------------------------------------------
---
With respect to your at symbols (@) being interpreted as apostrophes, I'm
not sure what is causing that since I'm not sure how you're inputting the
data. It certainly isn't normal behaviour for DB2 to convert @ to ' on the
fly. My best guess is that you are using a DB2 script that uses @ as the
statement delimiter and this has somehow gotten misinterpreted as a string
delimiter, probably because of user error in setting the delimiters. The
other prime suspect is that you may have a code page issue where the code
page you are using doesn't have the @ symbol in it and apostrophe is being
stored instead. I'm afraid I don't have much experience with code pages
though so I can't suggest how you can prove that, let alone fix it.

As far as changing apostrophes back to @ symbols, that should be pretty
easy. Here is a short script that creates a row which mistakenly contains an
apostrophe instead of an @ symbol:

----------------------------------------------------------------------------
-----------------------
connect to sample;

drop table temp01;
create table temp01
(id smallint not null,
name char(20) not null,
salary dec(9,2) not null,
email char(50) not null,
primary key(id));

Insert into temp01 (id, name, salary, email) values (1, 'O''Brien',
50000.00, 'Seamus''hotmai l.com');

select * from temp01;

----------------------------------------------------------------------------
------------------------------------

To repair the data, I would recommend doing the update on the basis of the
primary key since, by definition, it always refers to exactly one row so
that you can't inadvertently update any more than one row:

--------------------------------------------
update temp01
set email = 'S*****@hotmail .com'
where id = 1;
---------------------------------------------
select * from temp01;
However, the following would also work:

-----------------------------------------
update temp01
set email = 'S*****@hotmail .com'
where email = 'Seamus''hotmai l.com';
--------------------------------------------

The difference is that the second statement would change *every* occurrence
of Seamus'hotmail. com to Se****@hotmail. com.

I hope this helps.

Rhino

"James Foreman" <ja***********@ abcmail.co.uk> wrote in message
news:78******** *************** ***@posting.goo gle.com...
I've got a set of emails in a table, where sometimes they've failed to
input the @ properly.

Eg james.foreman'a bcmail.co.uk

How do I write a replace to deal with that?

Also, I've got a set of names in a table, all in lower case. I can
easily capitalise the first letter of each name, but if it's somebody
like O'Brien, I'd like to get that right too (so need to be able to
identify letters after a ' )

Thanks

James

Nov 12 '05 #2
"Rhino" <rh****@NOSPAM. sympatico.ca> wrote in message news:<2_******* ************@ne ws20.bellglobal .com>...
I'm not completely clear on what your question is: it sounds as if you are
concerned only with correcting the bad data and not with how it got there in
the first place. Frankly, I think you'll need to deal with both to fully
resolve the problem; there's no point in fixing the existing bad data
manually if the input procedures continue to allow bad data to be created in
your tables. Unfortunately, you haven't said anything about how you are
doing the input so this reply is going to get a bit wordy ;-)


Thanks for all the detail. Unfortunately we're stuck with fixing the
bad data because the input procedures will continue to be wrong for
some time; the email addresses are coming out of a legacy call centre
application; getting a change to this app to validate email addresses
on the way in just isn't going to happen. (Obviously, there's a
training issue as well here, but people being people, we'll never trap
every error - the @/' problem is probably touch typists used to
keyboards with the two symbols in reversed positions.)
Nov 12 '05 #3
"James Foreman" <ja***********@ abcmail.co.uk> wrote in message
news:78******** *************** ***@posting.goo gle.com...
I've got a set of emails in a table, where sometimes they've failed to
input the @ properly.

Eg james.foreman'a bcmail.co.uk

How do I write a replace to deal with that?

UPDATE t SET email = REPLACE(email,' ''','@')
WHERE LOCATE('''',ema il) > 0
Also, I've got a set of names in a table, all in lower case. I can
easily capitalise the first letter of each name, but if it's somebody
like O'Brien, I'd like to get that right too (so need to be able to
identify letters after a ' )


Regards
Paul Vernon
Business Intelligence, IBM Global Services
Nov 12 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
11911
by: J. Muenchbourg | last post by:
The following removes any unwanted apostrophes before being inserted into an sql database: Articletext = replace(articleText,"'","''") ..but if I need to remove all quotation marks, this doesnt work: Articletext = replace(articleText,""","''")
63
5914
by: Tristan Miller | last post by:
Greetings. Do any popular browsers correctly support <q>, at least for Western languages? I've noticed that Mozilla uses the standard English double-quote character, ", regardless of the lang attribute of the HTML document. Will any browsers render German-style quotes or French-style guillemots for lang="de" and lang="fr", respectively? Regards, Tristan
5
3463
by: Mateusz Loskot | last post by:
Hi, I'd like to ask how XML parsers should handle attributes which consists of &quot; entity as value. I know XML allows to use both: single and double quotes as attribute value terminator. That's clear. But how should parser react for such situation: I have CORDSYS element with string attribute which consists of value with many &quot; entities:
7
11597
by: Paradigm | last post by:
I am trying to create a recordset where some text fields are matching. The problem is that some of the text fields contain quotation marks. I have tried to create the sql string using replace eg. "SELECT * FROM MYTABLE WHERE REPLACE(MYFIELD,"""",".") = """ & REPLACE(MYTEXT,"""",".") & """" but this does not work. Trying to replace the quotation marks with some other character in this case the stop How can I embed the quotation marks in...
5
4915
by: james.igoe | last post by:
History: Took over development of Access project after half of app was developed. Continued the second half using same coding style as first developer, but improved upon code and flow, etc. Almost all of the insertions and deletions were done as DoCMD.RunSQL strSQL. Our current problem: All of our prototyping for the business tool was done in with
2
18697
by: Dustin | last post by:
I have a nested quotes issue I'm trying to resolve. Basically I need a 5th level nested quote for quoting the string argument to the getXMLFeed() function in the following: var myHTML = "<TR onMouseOver='return overlib(\"<A HREF=\'javascript:void(0)\' onClick=\'javascript:getXMLFeed(\"price\")\'>Price</A>\"'>"; How do you do a 5th level nested quote?
31
4896
by: The Bicycling Guitarist | last post by:
Hi. For many years I have been using &quot; for double quotation marks in the HTML code, but the opening and closing quotation marks render the same in my browser. I'm considering going through and using &ldquo; and &rdquo; (in pairs as needed) instead. Are there any *disadvantages* to doing so, besides the time it will take to make the change? Thanks.
4
18506
by: Lucanos | last post by:
Hey Guys, Probably a simple question, but one I am struggling with all the same. I know that in PHP you wrap a text string in apostrophes or quotations - (examples $variable = 'this string' OR $variable = "that string" ). What I am trying to figure is how to handle a string which contains both apostrophes and quotations already. Is there a something like CDATA is for XML?
3
8125
by: Royan | last post by:
Difference between quotation and apostrophe in PHP I wonder is there any difference between strings wrapped into quotation marks or into apostrophes and if so is there any situation when one is preferable to the other? -R.
0
10276
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10253
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10035
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9090
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7580
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6813
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5471
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5606
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4149
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 we have to send another system

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.