I'm a little baffled as to why this works:

CREATE TABLE #table1 (
        LName VARCHAR(100),
        FName VARCHAR(100),
        City VARCHAR(100)
)

CREATE TABLE #table2 (
        LName VARCHAR(100),
        FName VARCHAR(100),
        City VARCHAR(100),
        Suffix VARCHAR(100)
)

INSERT INTO #table1 ( LName, FName, City ) VALUES ( 'DOE JR', 'JOHN',
'PHOENIX' )
INSERT INTO #table1 ( LName, FName, City ) VALUES ( 'GATES', 'BILL',
'REDMOND' )
INSERT INTO #table1 ( LName, FName, City ) VALUES ( 'GORE III', 'AL',
'BACKWOODS' )
INSERT INTO #table1 ( LName, FName, City ) VALUES ( 'BRADSHAW', 'TERRY',
'HOUSTON' )

INSERT INTO #table2 ( LName, FName, City, Suffix ) VALUES ( 'DOE', 'JOHN',
'PHOENIX', 'JR' )
INSERT INTO #table2 ( LName, FName, City, Suffix ) VALUES ( 'GATES', 'BILL',
'REDMOND', '' )
INSERT INTO #table2 ( LName, FName, City, Suffix ) VALUES ( 'GORE', 'AL',
'BACKWOODS', 'III' )
INSERT INTO #table2 ( LName, FName, City, Suffix ) VALUES ( 'BRADSAW',
'TERRY', 'HOUSTON', '' )

SELECT t1.*, t2.*
FROM #table1 t1
INNER JOIN #table2 t2 ON ( t1.LName = t2.LName + ' ' + t2.Suffix )

The join clause for GATES would equate to this

'GATES' = 'GATES '

the extra space would be added. Now I remember reading something along the
lines that spaces after a varchar datatype would not be used for something,
in this case it looks like comparing 'GATES' to 'GATES ' will return true.

Here's a test using the above temp tables

SELECT * FROM #table1 WHERE LName = 'GATES '
SELECT * FROM #table1 WHERE LName = 'GATES   '
SELECT * FROM #table1 WHERE LName = ' GATES'

The first two return a row, the third doesn't. Interest, if a little
strange. Any one know why this happens?

Ade

-----Original Message-----
From: Adrian Lynch [mailto:[EMAIL PROTECTED]
Sent: 23 February 2005 23:43
To: CF-Talk
Subject: RE: OT-SQL matching


That's a great idea, do the join on a calculated field!

ON OnlyLastName + ' ' + Suffix = LastNameAndSufix

Is that what you're suggesting? If so and it works, I like :O)

Ade

-----Original Message-----
From: S. Isaac Dealey [mailto:[EMAIL PROTECTED]
Sent: 23 February 2005 23:45
To: CF-Talk
Subject: Re: OT-SQL matching


> For a CF page I am doing I need to out put matched
> results. However in one table I have last names with a
> suffix like "MOLINA JR" and in another table the last name
> and suffix are in different columns. I need to strip out
> the suffixes as well as the preceding space in the first
> column. Any ideas. I am trying a few thing and it is not
> working.

offhand

left join tabl2 on (table2.lastname = table1.lastname
        or table2.lastname like table1.lastname + ' %')

or if you want to match both

left join table2 on (
        (table2.lastname = table1.lastname and table2.suffix is null) or
        (table2.lastname + ' ' + table2.suffix = table1.lastname))

This is sql server syntax... it's gonna be different for every db...
it's an ugly, PURE EVIL BLACK AS COAL schema you have for the data
there... I have to deal with those at my job too -- hate 'em...


s. isaac dealey     954.927.5117
new epoch : isn't it time for a change?

--
No virus found in this outgoing message.
Checked by AVG Anti-Virus.
Version: 7.0.300 / Virus Database: 266.4.0 - Release Date: 22/02/2005


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Logware (www.logware.us): a new and convenient web-based time tracking 
application. Start tracking and documenting hours spent on a project or with a 
client with Logware today. Try it for free with a 15 day trial account.
http://www.houseoffusion.com/banners/view.cfm?bannerid=67

Message: http://www.houseoffusion.com/lists.cfm/link=i:4:196240
Archives: http://www.houseoffusion.com/cf_lists/threads.cfm/4
Subscription: http://www.houseoffusion.com/lists.cfm/link=s:4
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4
Donations & Support: http://www.houseoffusion.com/tiny.cfm/54

Reply via email to