Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
|
SQL Server 2000 General discussion of Microsoft SQL Server -- for topics that don't fit in one of the more specific SQL Server forums. version 2000 only. There's a new forum for SQL Server 2005.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server 2000 section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old February 6th, 2004, 04:17 PM
Authorized User
 
Join Date: Jun 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default Please Help - Tricky String Comparison

Hi All,

Thanks in advance for your replies.

I think this is a tricky comparison of string.

Let''s say I have the following tables and fields:

tbl01 tbl02
proid fullname proid fullname
------------- -------------
100 Parker, Peter S. 100 Parker, Peter S. M.
200 Jane, Mary T. 200 Jane, Mary K.
300 Wie, Michelle O. 300 Wie, Michel O.


'fullname' format is lastname, firstname initial.

I would like to return the record on
tbl01.proid=tbl02.proid
and tbl01.(lastname)=tbl02.(lastname)
and tbl01.(firstname)=tbl02.(firstname)

The above example would return 100 and 200.
300 would be excluded b/c 'Michele' <> 'Michel'.

If I had to do this in ASP or C#, then it''s easy.
I could easily split 'fullname' to get first and last name.
But I need to script this in T-SQL.
My box is MS SQL 7.0.

Please help if you know how to do this.
Appreciate all that post !

Thanks You.
 
Old February 6th, 2004, 09:57 PM
Authorized User
 
Join Date: Jun 2003
Posts: 60
Thanks: 0
Thanked 0 Times in 0 Posts
Default

I guess I'll answer my own post.
Using charindex helps to split up record into
last and first names.

The rest is just using inner join.

Here's the solution w/a little help from monosodiumg:

select *
from
  (select substring(record, 1, charindex(',', record) - 1) as surname,
  substring(record,(charindex(' ', record, 1) + 1), charindex(' ',record,(charindex(' ', record, 1) + 1 )) - (charindex(' ', record, 1) + 1) ) as first_name,
  provid
  from test01
  )t1
inner join
  (select substring(record, 1, charindex(',', record) - 1) as surname,
  substring(record,(charindex(' ', record, 1) + 1), charindex(' ',record,(charindex(' ', record, 1) + 1 )) - (charindex(' ', record, 1) + 1) ) as first_name,
  provid
  from test02
  )t2
      ON t1.provid=t2.provid
      AND t1.surname=t2.surname
      AND t1.first_name=t2.first_name






Similar Threads
Thread Thread Starter Forum Replies Last Post
JSTL String comparison probem! Plzzz help !! shimmeringtrinkets JSP Basics 0 February 26th, 2008 10:05 AM
String comparison arnabghosh Classic ASP Professional 1 June 29th, 2006 06:01 AM
Fuzzy string comparison (2) kobus XSLT 2 October 11th, 2004 07:28 AM
fuzzy string comparison kobus XSLT 0 September 22nd, 2004 05:47 AM
String Comparison rylemer Pro VB 6 9 July 29th, 2003 06:49 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.