Main Page | Report this Page
Computers Forum Index  »  Computer - Databases - IBM DB2  »  String functions in SQL...
Page 1 of 1    

String functions in SQL...

Author Message
Will Honea...
Posted: Thu Oct 15, 2009 9:38 am
Guest
I have a need to clean up some name records in a bunch of tables - over the
years names have been entered in all cap, lower case, mixed case, and some
really strange combinations of punctuation. This has left us with a mess
when trying to search/match client records by name.

The data in question may be entered as about any format I can think of - and
some I haven't.
'xxxx' -> 'Xxxx', 'xxxx xxxxx' -> 'Xxxx Xxxxx', 'xxxx xxxx xxxx' -> 'Xxxx
Xxxx Xxxx' etc. - you get the idea. Forcing the text to all upper or lower
case then using brute force with all sorts of LEFT, RIGHT, POSITION,
SUBSTR, LENGTH, etc yields a working result but is it ugly even before I
start testing for existence of error cases!

I could do this simply with a C procedure but I don't intend to maintain
this system much longer (fishing calls!) so an SQL solution would be
preferable for future maintenance reasons. Given the data sources, this
will be an ongoing issue. Can any of you SQL experts suggest a more elegant
solution than my kludge? (or point out where I missed the obvious).

--
Will Honea
 
Tonkuma...
Posted: Thu Oct 15, 2009 9:41 am
Guest
DB2 9.7 for Linux, UNIX, and Windows supports INITCAP function.
 
jefftyzzer...
Posted: Thu Oct 15, 2009 5:55 pm
Guest
On Oct 14, 10:38 pm, Will Honea <who... at (no spam) yahoo.com> wrote:
Quote:
I have a need to clean up some name records in a bunch of tables - over the
years names have been entered in all cap, lower case, mixed case, and some
really strange combinations of punctuation.  This has left us with a mess
when trying to search/match client records by name.

The data in question may be entered as about any format I can think of - and
some I haven't.
 'xxxx' -> 'Xxxx', 'xxxx xxxxx' -> 'Xxxx Xxxxx', 'xxxx xxxx xxxx' -> 'Xxxx
Xxxx Xxxx' etc. - you get the idea. Forcing the text to all upper or lower
case then using brute force with all sorts of LEFT, RIGHT, POSITION,
SUBSTR, LENGTH, etc yields a working result but is it ugly even before I
start testing for existence of error cases!

I could do this simply with a C procedure but I don't intend to maintain
this system much longer (fishing calls!) so an SQL solution would be
preferable for future maintenance reasons. Given the data sources, this
will be an ongoing issue. Can any of you SQL experts suggest a more elegant
solution than my kludge? (or point out where I missed the obvious).

--
Will Honea

If you don't have 9.7, is the two-step process of stripping-out non [A-
Z] (and space) characters and then shifting everything to uppercase
more than you want to do?

-Jeff
 
Tonkuma...
Posted: Thu Oct 15, 2009 10:14 pm
Guest
On Oct 16, 5:09 am, Will Honea <who... at (no spam) yahoo.com> wrote:
Quote:
The database is on 9.5 at the moment but I have a new server in build with 9.7 so that should
provide the function for a quick and dirty.
If you are not on DB2 9.7 for LUW,

you can use INITCAP UDF in Sample UDFs for Migration:
http://www.ibm.com/developerworks/data/library/samples/db2/0205udfs/index.html
 
Will Honea...
Posted: Fri Oct 16, 2009 12:09 am
Guest
Tonkuma wrote:

Quote:
DB2 9.7 for Linux, UNIX, and Windows supports INITCAP function.

Thank you sir, that does indeed solve the problem. The database is on 9.5
at the moment but I have a new server in build with 9.7 so that should
provide the function for a quick and dirty. Looks like I was re-inventing
the wheel.

--
Will Honea
 
Lennart...
Posted: Fri Oct 16, 2009 5:51 am
Guest
On 15 Okt, 11:41, Tonkuma <tonk... at (no spam) fiberbit.net> wrote:
Quote:
DB2 9.7 for Linux, UNIX, and Windows supports INITCAP function.

Tonkuma, I can't seem to find the docs for this function. Can you
provide a link to it?


/Lennart
 
Tonkuma...
Posted: Fri Oct 16, 2009 6:22 am
Guest
On Oct 16, 2:51 pm, Lennart <erik.lennart.jons... at (no spam) gmail.com> wrote:
Quote:
On 15 Okt, 11:41, Tonkuma <tonk... at (no spam) fiberbit.net> wrote:

DB2 9.7 for Linux, UNIX, and Windows supports INITCAP function.

Tonkuma, I can't seem to find the docs for this function. Can you
provide a link to it?

/Lennart
You can find it by serching "INITCAP" in "IBM DB2 9.7 for Linux, UNIX,

and Windows Information Center": http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/index.jsp
 
Henrik Loeser...
Posted: Fri Oct 16, 2009 7:34 am
Guest
On Oct 16, 8:22 am, Tonkuma <tonk... at (no spam) fiberbit.net> wrote:
Quote:
On Oct 16, 2:51 pm, Lennart <erik.lennart.jons... at (no spam) gmail.com> wrote:> On 15 Okt, 11:41, Tonkuma <tonk... at (no spam) fiberbit.net> wrote:

DB2 9.7 for Linux, UNIX, and Windows supports INITCAP function.

Tonkuma, I can't seem to find the docs for this function. Can you
provide a link to it?

/Lennart

You can find it by serching "INITCAP" in "IBM DB2 9.7 for Linux, UNIX,
and Windows Information Center":http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/index.jsp

The direct link is here:
http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db2.luw.sql.ref.doc/doc/r0053527.html

Henrik
 
Will Honea...
Posted: Fri Oct 16, 2009 10:40 am
Guest
Tonkuma wrote:

Quote:
On Oct 16, 5:09 am, Will Honea <who... at (no spam) yahoo.com> wrote:
The database is on 9.5 at the moment but I have a new server in build
with 9.7 so that should provide the function for a quick and dirty.
If you are not on DB2 9.7 for LUW,
you can use INITCAP UDF in Sample UDFs for Migration:

http://www.ibm.com/developerworks/data/library/samples/db2/0205udfs/index.html


Again, Thank you. I was going to ask how you found this - but then I
noticed the author. Now I can get on with things without mucking around
migrating things back and forth (the new server is a tad flaky right now)
but I still need to update things around here.

BTW, INITCAP is documented in the 9.7 Info Center - once you find the
appropriate section.

--
Will Honea
 
Will Honea...
Posted: Fri Oct 16, 2009 10:44 am
Guest
jefftyzzer wrote:

Quote:
If you don't have 9.7, is the two-step process of stripping-out non [A-
Z] (and space) characters and then shifting everything to uppercase
more than you want to do?

Yep, since the 9.7 INITCAP() function does exactly what I want with no
hassle.

--
Will Honea
 
Lennart...
Posted: Fri Oct 16, 2009 10:59 am
Guest
On 16 Okt, 09:34, Henrik Loeser <goo... at (no spam) 4loeser.net> wrote:
Quote:
On Oct 16, 8:22 am, Tonkuma <tonk... at (no spam) fiberbit.net> wrote:

On Oct 16, 2:51 pm, Lennart <erik.lennart.jons... at (no spam) gmail.com> wrote:> On 15 Okt, 11:41, Tonkuma <tonk... at (no spam) fiberbit.net> wrote:

DB2 9.7 for Linux, UNIX, and Windows supports INITCAP function.

Tonkuma, I can't seem to find the docs for this function. Can you
provide a link to it?

/Lennart

You can find it by serching "INITCAP" in "IBM DB2 9.7 for Linux, UNIX,
and Windows Information Center":http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/index.jsp

The direct link is here:http://publib.boulder.ibm.com/infocenter/db2luw/v9r7/topic/com.ibm.db...

Henrik

Thanx, obviously I did something wrong when searching the docs before.


/Lennart
 
jefftyzzer...
Posted: Fri Oct 16, 2009 11:13 pm
Guest
On Oct 15, 11:44 pm, Will Honea <who... at (no spam) yahoo.com> wrote:
Quote:
jefftyzzer wrote:
If you don't have 9.7, is the two-step process of stripping-out non [A-
Z] (and space) characters and then shifting everything to uppercase
more than you want to do?

Yep, since the 9.7 INITCAP() function does exactly what I want with no
hassle.

--
Will Honea

No argument there!
 
 
Page 1 of 1    
All times are GMT
The time now is Fri Dec 11, 2009 9:19 am