Connecting Tech Pros Worldwide Forums | Help | Site Map

Query syntax

Will Honea
Guest
 
Posts: n/a
#1: Nov 12 '05
Two tables - table A has a column of full names (First MI Last), table
B has 2 columns (First, Last) but no middle (and yes, I'd like to
strangle the idiot who designed it!). Is there a syntax that will
allow a query on something similar to:

A.name like (B.first || % || B.last)?

Everything I try seems to wind up with errors where on operand is not
a string.

--
Will Honea

fred.sobotka@gmail.com
Guest
 
Posts: n/a
#2: Nov 12 '05

re: Query syntax


I'm assuming that the columns are CHAR columns, so I've included RTRIM.

CREATE TABLE a (name CHAR(50));
CREATE TABLE b (first CHAR(20), last CHAR(20));

INSERT INTO a VALUES('John Q. Public');

INSERT INTO b VALUES('John', 'Public');

SELECT a.name, 'MATCHES', b.first, b.last
FROM a,b
WHERE LOCATE(RTRIM(b.first||' '), a.name) = 1
AND LOCATE(RTRIM(' '||b.last), a.name) = LENGTH(RTRIM(a.name)) -
LENGTH(RTRIM(b.last))
;

NAME 2 FIRST
LAST
-------------------------------------------------- -------
-----------------------------------------------------------------------
John Q. Public MATCHES John
Public

I'll serve as a defense witness if you do decide to strangle that
original designer.

Fred
frsconsulting.com

Will Honea
Guest
 
Posts: n/a
#3: Nov 12 '05

re: Query syntax


On Thu, 26 May 2005 06:48:49 UTC fred.sobotka@gmail.com wrote:
[color=blue]
> I'm assuming that the columns are CHAR columns, so I've included RTRIM.
>
> CREATE TABLE a (name CHAR(50));
> CREATE TABLE b (first CHAR(20), last CHAR(20));
>
> INSERT INTO a VALUES('John Q. Public');
>
> INSERT INTO b VALUES('John', 'Public');
>
> SELECT a.name, 'MATCHES', b.first, b.last
> FROM a,b
> WHERE LOCATE(RTRIM(b.first||' '), a.name) = 1
> AND LOCATE(RTRIM(' '||b.last), a.name) = LENGTH(RTRIM(a.name)) -
> LENGTH(RTRIM(b.last))
> ;
>
> NAME 2 FIRST
> LAST
> -------------------------------------------------- -------
> -----------------------------------------------------------------------
> John Q. Public MATCHES John
> Public
>
> I'll serve as a defense witness if you do decide to strangle that
> original designer.[/color]

Thanks, Fred. Needless to say, I've been away from SQL too long - I
really could use a "for Dummies" cheat sheet. There used to be a good
one on line but I've lost the url so that's no help. Now, if I can
just finagle enough info out of the rest of the tables to
differentiate 130 (out of 25k) duplicate A.name and 1470 (of 42k)
duplicate B.first/last entries I may get this usable - but I see some
manual entries in my immediate future. That's what happens when you
volunteer, I guess.

--
Will Honea
fred.sobotka@gmail.com
Guest
 
Posts: n/a
#4: Nov 12 '05

re: Query syntax


Hi Will,

I'm a big fan of a free book by Graeme Birchall called the DB2 UDB
Cookbook. Mr. Birchall has kept the book up to date with the latest
version of DB2, and it's a pretty good read.

http://ourworld.compuserve.com/homep...l/HTM_COOK.HTM

Good luck,

Fred
frsconsulting.com

Closed Thread