Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > SQL Server > SQL Server 2000 > SQL Server 2000
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old February 6th, 2004, 03:17 PM
Authorized User
 
Join Date: Jun 2003
Location: Rochester, NY, USA.
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.
Reply With Quote
  #2 (permalink)  
Old February 6th, 2004, 08:57 PM
Authorized User
 
Join Date: Jun 2003
Location: Rochester, NY, USA.
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

Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
JSTL String comparison probem! Plzzz help !! shimmeringtrinkets JSP Basics 0 February 26th, 2008 09: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



All times are GMT -4. The time now is 10:44 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.