473,545 Members | 2,081 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Strip titles from varchar string

Hi.

I have a large Address table, NAME col. is varchar and has titles like:
'MR. ABC and MRS. MMM' want to update to: 'ABC and MMM'
'MR. ABC and MRS. MMM' want to update to be: 'ABC and MMM'
'DR. KKK MMM' want to update to be: 'KKK MMM'

titles are long list (english, french..)

any ideas of a sql script or a function?
I am using DB2 udb 8.2 on aix. code is sql Stored Procedures

Thanks
Fayez

Nov 12 '05 #1
4 2904

"fayez" <fs****@gmail.c om> wrote in message
news:11******** *************@f 14g2000cwb.goog legroups.com...
Hi.

I have a large Address table, NAME col. is varchar and has titles like:
'MR. ABC and MRS. MMM' want to update to: 'ABC and MMM'
'MR. ABC and MRS. MMM' want to update to be: 'ABC and MMM'
'DR. KKK MMM' want to update to be: 'KKK MMM'

titles are long list (english, french..)

any ideas of a sql script or a function?
I am using DB2 udb 8.2 on aix. code is sql Stored Procedures

Stored procedures and user-defined functions are intended for tasks that
you will do again and again. Therefore, if you want to *permanently* remove
the titles from the database, I think it would make more sense to create a
batch job to do a one-shot mass of your tables. A stored procedure or
used-defined function would make more sense if you simply want to *ignore*
the titles for some queries and return just the rest of the name.

Is there any possibility of restructuring your tables? Many queries on your
tables would be easier if you had separate columns for first name, last
name, middle names, title, "generation al identifier" (e.g. the "Jr." in
"John Doe Jr." or the "III" in "John Doe III"). Then, you could pick or
choose whichever aspects of the name you wanted in each case. You would also
find it easier to determine which part of the name was which. For instance,
if you saw the name "Forrest Sawyer" or "Jing Lee", you wouldn't have to
guess which was the first name and which was the last.

If you must stay with the single column to contain all the name information,
you would have to write logic like this (pseudo-code):

---

select name from customer_table;

if (first-word-of-name = 'Mr.') then short_name = rest-of-name
else if (first-word-of-name = 'Mrs.') then short_name = rest-of-name
etc. etc.

display rest-of-name in report or query result
---

But be careful; this will be vulnerable to occasional logical errors that
can't easily be handled in programs. For example, there is an actress named
Missy Crider. If she were in your table, your program would probably simply
strip off the first part of her first name and leave it as "y Crider". That
is obviously wrong and might upset her if she were a customer.

Rhino
Nov 12 '05 #2
Hello.

------
declare global temporary table titles (t varchar(10) not null) with
replace on commit preserve rows;
declare global temporary table strings (s varchar(50) not null) with
replace on commit preserve rows;
declare global temporary table repl(orig varchar(50), new varchar(50))
with replace on commit preserve rows;

insert into session.titles values ('MR.'), ('MRS.'), ('DR.');
insert into session.strings values
('MR.AAA AND DR.BBB'),
('MR.AAA AND MRS.BBB'),
('MRS.DDD AND DR.FFF'),
('DR.CCC AND GGG'),
('EEE');

-- temporary table for replacement
insert into session.repl (orig, new)
WITH A(ORIG, ITER, S) AS (
SELECT S.S, 1, VARCHAR(REPLACE (S.S, T.T, ''), 50)
FROM SESSION.TITLES T
JOIN SESSION.STRINGS S ON REPLACE(S.S, T.T, '')!=S.S
UNION ALL
SELECT A.ORIG, A.ITER+1, VARCHAR(REPLACE (A.S, T.T, ''), 50)
FROM A, SESSION.TITLES T
WHERE REPLACE(A.S, T.T, '')!=A.S
)
SELECT DISTINCT ORIG, S
FROM A
WHERE ITER = (SELECT MAX(ITER) FROM A A2 WHERE A2.ORIG=A.ORIG) ;

update session.strings s
set s.s = (select r.new from session.repl r where r.orig=s.s)
where exists (select r.new from session.repl r where r.orig=s.s);
------

Sincerely,
Mark B.

Nov 12 '05 #3
How about this?
BEGIN ATOMIC
FOR st AS
SELECT title
FROM titles_table
DO
UPDATE Address_table
SET name = REPLACE(name, title, '');
END FOR;
END!

Nov 12 '05 #4
Thanks for the idea, woking fine

Nov 12 '05 #5

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

Similar topics

9
18052
by: scott | last post by:
I have a field with datetime values like below LISTING 1. Can someone help me write code strip the time part so only values like "7/15/2005" will be left. Note - We must be able to strip dates with double digit months and days, so i can't just use the right function with a hard coded parameter. LISTING 1
6
2146
by: Mark Miller | last post by:
I have a scheduled job that uses different XSL templates to transform XML and save it to disk. I am having problems with the code below. The problem shows up on both my development machine (Windows XP Pro SP 1, .Net Framework 1.1) and on our production server (Windows 2K SP 4, .Net Framework 1.1). I have simplified the code and data to isolate...
3
11673
by: alex.mcshane | last post by:
Hi - I would be grateful for any advice on the following. Within DB2 for OS/390, the STRIP Scaler Function is available. Its function is, for example, to remove leading zeros from a string. For example: - Strip(Char(Digits(v_cntrct_no_seed)),L,'0') - v_cntrct_no_seed is defined as Integer - Char and Digits return a character...
5
8707
by: dan.j.weber | last post by:
I'm using Python 2.3.5 and when I type the following in the interactive prompt I see that strip() is not working as advertised: >>>s = 'p p:p' >>>s.strip(' :') 'p p:p' Is this just me or does it not work? I want to get rid of all ' ' and ':' in the string. I've checked the doc and from what I can tell this is what strip() is supposed to...
6
2542
by: rtilley | last post by:
s = ' qazwsx ' # How are these different? print s.strip() print str.strip(s) Do string objects all have the attribute strip()? If so, why is str.strip() needed? Really, I'm just curious... there's a lot don't fully understand :)
2
10824
by: michael.bierenfeld | last post by:
Hello, we are currently porting some sql programs from vm/vse to aix. On The VSE Machine (DB2) the following is valid : -lots of crap - but in the where clause of the statement : WHERE JOBDESC = (STRIP(:HV-JOB) CONCAT '/in')
2
2622
by: tshad | last post by:
Is there an easy way to strip HTML tags from Text to get just the plain text? I am using a program called FreeTextBox that lets you format Text in a TextBox. It does this by adding HTML tags (<b>, <u>,<span> etc) to the code. The problem is that it is a problem since I am putting the text in a varChar(8000). The HTML adds a lot...
6
2340
by: eight02645999 | last post by:
hi can someone explain strip() for these : 'example' when i did this: 'abcd,words.words'
3
2360
by: Colin J. Williams | last post by:
The Library Reference has strip( ) Return a copy of the string with the leading and trailing characters removed. The chars argument is a string specifying the set of characters to be removed. If omitted or None, the chars argument defaults to removing whitespace. The chars argument is not a
0
7468
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7401
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7808
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...
0
7757
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...
0
5972
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...
1
5329
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...
0
3450
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...
0
3443
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1884
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.