SQL Clone
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


soundex function


soundex function

Author
Message
vipulhimanshu
vipulhimanshu
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 6
What exactly and on what basis does the soundex function returns the integer values.

I read through msdn but it only tells that it doesn't considers vowels in the strings.

But what I exactly want to know is what logic is used during comparison of two strings behind th scene.
GSquared
GSquared
SSC-Insane
SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)SSC-Insane (23K reputation)

Group: General Forum Members
Points: 23391 Visits: 9730
There's an entry in Wikipedia about soundex. It has what you're looking for.

- Gus "GSquared", RSVP, OODA, MAP, NMVP, FAQ, SAT, SQL, DNA, RNA, UOI, IOU, AM, PM, AD, BC, BCE, USA, UN, CF, ROFL, LOL, ETC
Property of The Thread

"Nobody knows the age of the human race, but everyone agrees it's old enough to know better." - Anon
vipulhimanshu
vipulhimanshu
Forum Newbie
Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)Forum Newbie (5 reputation)

Group: General Forum Members
Points: 5 Visits: 6
Thanks. This is exactly what I am looking for
Bill Talada
Bill Talada
Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1161 Visits: 1996
Here is my first attempt to make soundex more selective:

Algorithm sqlserver uses:
Replace consonants with digits as follows (but do not change the first letter):
b, f, p, v => 1
c, g, j, k, q, s, x, z => 2
d, t => 3
l => 4
m, n => 5
r => 6
Collapse adjacent identical digits into a single digit of that value.
Remove all non-digits after the first letter.
Return the starting letter and the first three remaining digits.
If needed, append zeroes to make it a letter and three digits.

Lets extend this to 5 in length to make it more selective.
On lastname data I see a selectivity increase from 1 in 3000 to 1 in 10000.

Function contains no error checking and is not optimized.


drop function dbo.soundex5;
go

create function Soundex5( @name varchar(30))
returns varchar(5)
as
begin

declare
@out varchar(20),
@i int,
@vc varchar(1);

set @name = @name + '00000';

set @out = left(@name,1);

set @i = 2;
while @i <= len(@name)
begin
set @vc = substring(@name, @i, 1)

set @out = @out +
case
when charindex(@vc, 'bfpv') > 0 then '1'
when charindex(@vc, 'cgjkqsxz') > 0 then '2'
when charindex(@vc, 'dt') > 0 then '3'
when charindex(@vc, 'l') > 0 then '4'
when charindex(@vc, 'mn') > 0 then '5'
when charindex(@vc, 'r') > 0 then '6'
when charindex(@vc, '0') > 0 then '0'
else ''
end;

set @i = @i + 1;
end

-- ignore similar consecutive sounds
set @out = REPLACE(@out,'11','1');
set @out = REPLACE(@out,'22','2');
set @out = REPLACE(@out,'33','3');
set @out = REPLACE(@out,'44','4');
set @out = REPLACE(@out,'55','5');
set @out = REPLACE(@out,'66','6');

return left(@out,5);

end
go



Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search