Connecting Tech Pros Worldwide Help | Site Map
 
 
LinkBack Thread Tools Search this Thread
  #1  
Old November 12th, 2005, 07:25 AM
James Foreman
Guest
 
Posts: n/a
Default 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'abcmail.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
  #2  
Old November 12th, 2005, 07:25 AM
Rhino
Guest
 
Posts: n/a
Default Re: Handling quotation marks and apostrophes

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(?, ?, ?)";



PreparedStatement pstmt02 = null;

try {

pstmt02 = conn01.prepareStatement(insertSQL);

}

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



int numRowsInserted = 0;

try {

pstmt02.setInt(1, 1);

pstmt02.setString(2, "O'Brien");

pstmt02.setBigDecimal(3, 50000.00);

numRowsUpdated = pstmt02.executeUpdate();

}

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''hotmail.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 = 'Seamus@hotmail.com'
where id = 1;
---------------------------------------------
select * from temp01;


However, the following would also work:

-----------------------------------------
update temp01
set email = 'Seamus@hotmail.com'
where email = 'Seamus''hotmail.com';
--------------------------------------------

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

I hope this helps.

Rhino

"James Foreman" <james.foreman@abcmail.co.uk> wrote in message
news:7831db77.0405150617.7f2854c4@posting.google.c om...[color=blue]
> I've got a set of emails in a table, where sometimes they've failed to
> input the @ properly.
>
> Eg james.foreman'abcmail.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[/color]


  #3  
Old November 12th, 2005, 07:27 AM
James Foreman
Guest
 
Posts: n/a
Default Re: Handling quotation marks and apostrophes

"Rhino" <rhino1@NOSPAM.sympatico.ca> wrote in message news:<2_4qc.5169$325.470022@news20.bellglobal.com> ...[color=blue]
> 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 ;-)
>[/color]

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.)
  #4  
Old November 12th, 2005, 07:27 AM
Paul Vernon
Guest
 
Posts: n/a
Default Re: Handling quotation marks and apostrophes

"James Foreman" <james.foreman@abcmail.co.uk> wrote in message
news:7831db77.0405150617.7f2854c4@posting.google.c om...[color=blue]
> I've got a set of emails in a table, where sometimes they've failed to
> input the @ properly.
>
> Eg james.foreman'abcmail.co.uk
>
> How do I write a replace to deal with that?[/color]


UPDATE t SET email = REPLACE(email,'''','@')
WHERE LOCATE('''',email) > 0
[color=blue]
> 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 ' )[/color]

Regards
Paul Vernon
Business Intelligence, IBM Global Services


 

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

Popular Articles

What is Bytes?

We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights. Get the best answers to your questions from over 205,335 network members.