Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion Groups
DB Engine
SQL ServerMSDESQL Server CE
Services
Analysis (Data Mining)Analysis (OLAP)DTSIntegration ServicesNotification ServicesReporting Services
Programming
CLRConnectivitySQLXML
Other Technologies
ClusteringEnglish QueryFull-Text SearchReplicationService Broker
General
Data WarehousingPerformanceSecuritySetupSQL Server ToolsOther SQL Server Topics
DirectoryUser Groups
Related Topics
MS AccessOther DB ProductsMS Server Products.NET DevelopmentVB DevelopmentJava DevelopmentMore Topics ...

SQL Server Forum / Programming / SQL / December 2008

Tip: Looking for answers? Try searching our database.

User Defined Function for parsing and comparing last name in the     table.

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
msftsqldba@gmail.com - 31 Dec 2008 01:06 GMT
I need quick help and a UDF for comparing last name in the database
table to a last name in the file (one at a time). File can contain
names in any of the following ways.

Joseph Edna (interrested in parsing Edna only)
Joseph Charles Edna (interested in Edna only)
Joseph and Edna Jr (interested in Edna only)
Joseph C Edna (Interested in Edna only)
Joseph Edna # Darwin C Edera (interested in comparing both Edna and
Ederaa, Starting with Edna first if that is false compare Edera)
Joseph Edna jr # Darwin Edera (Interested in both Edna and Edera
similar to the above)

Thanks in advance for all your help.
Michael Cole - 31 Dec 2008 03:01 GMT
> I need quick help and a UDF for comparing last name in the database
> table to a last name in the file (one at a time). File can contain
[quoted text clipped - 8 lines]
> Joseph Edna jr # Darwin Edera (Interested in both Edna and Edera
> similar to the above)

Don't forget names like Eamonn de Valera (the last name is "de Valera", not
just "Valera".
Should I also mention a name such as "Piet van der Volk", were the last name
is "van der Volk", and compare that to a name such as "George Van Morrison",
where the last name is "Morrison"?

Signature

Regards

Michael Cole

Alex Kuznetsov - 31 Dec 2008 04:01 GMT
On Dec 30, 7:06 pm, msftsql...@gmail.com wrote:
> I need quick help and a UDF for comparing last name in the database
> table to a last name in the file (one at a time). File can contain
[quoted text clipped - 10 lines]
>
> Thanks in advance for all your help.

You need to parse "Joseph Edna" into first/middle/last name on the
client side, before you save the data. LastName column should store
only "Edna". That simplifies your task.
msftsqldba@gmail.com - 31 Dec 2008 11:58 GMT
> On Dec 30, 7:06 pm, msftsql...@gmail.com wrote:
>
[quoted text clipped - 16 lines]
> client side, before you save the data. LastName column should store
> only "Edna". That simplifies your task.

Here is my sample data. I need to do this through SQL with UDF and I
do not have a choice of doing this through client side.

ID    Name
1      Joseph Edna
2      Ralph Nader and Mary Sabad
3      Charles Nagy or Joe Gilly Jr
4      Randal Mary Cunningham
--------------------------------

----------------------------

In each of the above case I need to extract only last name only. In
case of more than one last name (for ex in record # 2) I need to get
both Nader, Sabad one at a time..
Erland Sommarskog - 31 Dec 2008 13:55 GMT
> Here is my sample data. I need to do this through SQL with UDF and I
> do not have a choice of doing this through client side.

If you are on SQL 2005, you can still do this in C# or VB with help of
a CLR function.

While never is a fun exercise, a 3GL language is likely to be more
efficient, both in terms of execution and development.

Then again, do this in T-SQL? Well, first a table-valued function that
splits up the string on spaces (look at my web site for such functions:
http://www.sommarskog.se/arrays-in-sql.html) Use a function that also
returns the list position. Inserts all parts into a table, keep the list
position. Then you have a table that defines strings to ignore: "Jr", "and"
and so on. Delete such ignorable strings. Also delete all strings that
are to short to be a last name.

Use the row_number function to number the remainging rows from 1 starting
with the row with the highest list position. Assume now that strings 1, 3, 5
and so one are the last names.

In any case, you should use the language you are the most comfortable with,
because it will take you long time, and several reiterations until you
have something which is working good enough. It will never be exact.

Signature

Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Links for SQL Server Books Online:
SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx
SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx
SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx

--CELKO-- - 31 Dec 2008 04:15 GMT
Do not do this yourself.  Names are very tricky.  UDFs are
proprietary.

Get a copy of the book MATH, MYTH & MAGIC OF NAME SEARCH AND MATCHING
from www.searchsoftware.com and see how the pros do it.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2010 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.