Pages

Monday, October 29, 2012

Soundex in SQL ( Phonetic algorithm)

Introduction

phonetic algorithm matches two different words with similar pronunciation to the same code, which allows phonetic similarity based word set comparison and indexing.

Often it is quite difficult to find atypical name (or surname) in the database, for example:

— Hey, John, look for Adolf Schwarzenegger.
— Adolf Shwardseneger? There is no such person!
In this case, the use of phonetic algorithms can significantly simplify the problem.

Soundex algorithm is very useful for searching in lists of people in databases, as well as for using in a spell checker. They are often used in combination with the algorithms of fuzzy search, providing users with a handy search by name and surname in databases, lists of people and so on.

soundex sql soundex sql soundex sql soundex sql soundex in sql soundex in sql soundex in sql soundex in sql

Soundex

One of the first algorithms was Soundex invented in the 1910s by Robert Russell. This algorithm (its American version) matches words to the numerical index like A126. Its working principle is based on the partition of consonants in groups with ordinal numbers, which are then compiled to the resulting value. Later several improvements was suggested.


Soundex Coding Guide


Number Represents the Letters
1 B, F, P, V
2 C, G, J, K, Q, S, X, Z
3 D, T
4 L
5 M, N
6 R

Disregard the letters A, E, I, O, U, H, W, and Y. 


Every soundex code consists of a letter and three numbers, such as W-252. The letter is always the first letter of the surname. The numbers are assigned to the remaining letters of the surname according to the soundex guide shown below. Zeroes are added at the end if necessary to produce a four-character code. Additional letters are disregarded. 

Examples:
  • Washington is coded W-252 (W, 2 for the S, 5 for the N, 2 for the G, remaining letters disregarded).
  • Lee is coded L-000 (L, 000 added).
image  
Examples :
soundex sql server soundex sql server soundex code soundex code soundex code soundex code
F234 → Fusedale.
G535 → Genthner, Gentner, Gianettini, Gunton.
G640 → Garlee, Garley, Garwell, Garwill, Gerrell, Gerrill, Giral, Gorelli, Gorioli, Gourlay, Gourley, Gourlie, Graal, Grahl, Grayley, Grealey, Greally, Grealy, Grioli, Groll, Grolle, Guerola, Gurley.
H326 → Hadcroft, Hadgraft, Hatchard, Hatcher, Hatzar, Hedger, Hitscher, Hodcroft, Hutchcraft.
P630 → Parade, Pardew, Pardey, Pardi, Pardie, Pardoe, Pardue, Pardy, Parradye, Parratt, Parrett, Parrot, Parrott, Pearde, Peart, Peaurt, Peert, Perdue, Peret, Perett, Perot, Perott, Perotti, Perrat, Perrett, Perritt, Perrot, Perrott, Pert, Perutto, Pirdue, Pirdy, Pirot, Pirouet, Pirt, Porrett, Porritt, Port, Porte, Portt, Prate, Prati, Pratt, Pratte, Pratty, Preddy, Preedy, Preto, Pretti, Pretty, Prewett, Priddey, Priddie, Priddy, Pride, Pridie, Pritty, Prott, Proud, Prout, Pryde, Prydie, Purdey, Purdie, Purdy.


soundex number soundex number soundex number soundex number soundex sql server soundex sql server 

Soundex in SQL:

ALTER FUNCTION fn_soundex(@Getname VARCHAR(500))
RETURNS VARCHAR(500)
BEGIN

    -- To Store First Letter

    DECLARE @GetFirstLetter VARCHAR(20);    
    
    -- To Store Soundex Code
    DECLARE @SetSoundexCode VARCHAR(20);    
    
    -- To Find length of string
    DECLARE @Code_len INT;                    

    -- Default Value

    SET @SetSoundexCode = '0'                        
    
    -- Get First Letter
    SET @GetFirstLetter = substring(@Getname,1,1)    
    
    -- Copy Remain Character to another String
    SET @Getname = substring(@Getname,2,len(@Getname))    
    
    -- Assign Code according to Letter
    
    SET @Getname = replace(@Getname,'A',0)
    SET @Getname = replace(@Getname,'E',0)
    SET @Getname = replace(@Getname,'I',0)
    SET @Getname = replace(@Getname,'O',0)
    SET @Getname = replace(@Getname,'U',0)
    SET @Getname = replace(@Getname,'H',0)
    SET @Getname = replace(@Getname,'W',0)
    SET @Getname = replace(@Getname,'Y',0)
    
    SET @Getname = replace(@Getname,'B',1)
    SET @Getname = replace(@Getname,'F',1)
    SET @Getname = replace(@Getname,'P',1)
    SET @Getname = replace(@Getname,'V',1)

    SET @Getname = replace(@Getname,'C',2)

    SET @Getname = replace(@Getname,'G',2)
    SET @Getname = replace(@Getname,'J',2)
    SET @Getname = replace(@Getname,'K',2)
    SET @Getname = replace(@Getname,'Q',2)
    SET @Getname = replace(@Getname,'S',2)
    SET @Getname = replace(@Getname,'X',2)
    SET @Getname = replace(@Getname,'Z',2)

    SET @Getname = replace(@Getname,'D',3)

    SET @Getname = replace(@Getname,'T',3)
    
    SET @Getname = replace(@Getname,'L',4)
    
    SET @Getname = replace(@Getname,'M',5)
    SET @Getname = replace(@Getname,'N',5)
    
    SET @Getname = replace(@Getname,'R',6)
    
    -- Get Length of String
    SET @Code_len = len(@Getname)            
    
    -- Remove Space from both side
    SET @Getname = ltrim(rtrim(@Getname))    

    -- Check if length is greater then zero

    WHILE @Code_len > 0
    BEGIN
        -- Compare two letter at same time to check duplicate
        -- If character is repeating character then make it Zero...
        -- We will remove Zero at the End
        IF charindex(substring(@Getname,@Code_len,1),substring(@Getname,@Code_len-1,1)) > 0  
            SET @SetSoundexCode = @SetSoundexCode + '0'
        ELSE
            SET @SetSoundexCode = @SetSoundexCode + substring(@Getname,@Code_len,1)
        
        SET @Code_len = @Code_len - 1
    END

    SET @SetSoundexCode = @GetFirstLetter + reverse(replace(@SetSoundexCode,'0',''))+'000'


    RETURN LEFT(@SetSoundexCode,4)


END

GO


There are lot many variance in Soundex Search algorithm. 
Referenced from SOUNDEX (Transact-SOL)     soundex sql server soundex sql server
Useful Link:
http://www.archives.gov/research/census/soundex.html
soundex function soundex function soundex function soundex function sql soundex sql soundex sql soundex sql soundex

Saturday, October 20, 2012

SQLDbx Step by Step

Hello Guys,

As I promised you, Today I will give you detail information on SQLDbx Tool step by step.
  • SQLDbx is too much portable.
  • With SQLDbx, you can connect to any database listed below in image.
 
  • As showing in Image, It will show you connected Server name in Server Panel.
  • It allows you to change database directly from Database Selection Panel and Search in Text area from Search Panel.
  • It allows you to filter table and other objects from left panel where filter icon is available for selected objects.
  • It also provides Auto Intellisense.

  • It allows to transpose data in Result tab and to export data from Result tab.
 
  • It allows to Freeze column in Result tab.
  • It shows data type for each column in Result tab and it allows to sort data by clicking on Column header.

  • It allows to export data directly from Result grid as well as allows to single click data export in various format.

  • It allows to generate various scripts from Result tab directly like Select, Insert, Delete, Update etc...


  • It allows to change date format and other format into result tab directly.
 
  • It can generate Select, Insert, Update script with single click based on table.



These is all about SQLDbx what i know.
Please feel free to email me for any problem or concern.
what is sql server            what is sql server            what is sql server                 what is sql server       software database           software database             software database                 software database            database software           database software             database software                database software      sql tools       sql tools       sql tools       sql tools       tool for sql     tool for sql     tool for sql     tool for sql     

    Thursday, October 18, 2012

    Nice Tool for Database Developer

    SQLDbx

    SqlDbx is a fast and easy to use database SQL development software.

    You can connect to any database with the help of SQLDbx.

    Features:

    • You can connect major Database Servers including Microsoft, Sybase ASE, Oracle and IBM DB2/UDB
    • Auto Intellisense
    • SQLDbx have facility to auto complete word and Intellisense to find Table and Column accordingly.
    • Automatically highlight matching parenthesis for BEGIN/END, IF/END IF, CASE/END, ... SQL blocks
    • It supports x86 and x64 Versions
    • It can generate Select, Insert, Update, Create data modification script from result grid.
    • It allows to sort data directly in result grid and even we can export data to Excel and CSV format directly from result grid.
    • It stored all SQL executed statements.
    • With SQLDbx, It is very easy to filter Table, Store Procedure, Views, System Objects.
    • We can directly transpose data in Result Tab.
    • It allows you to freeze column in Result Tab.
    • It allows to update data directly in Result Grid.
    • It allows you to see result in text format or Tabular Grid
    • SQLDbx is very Portable (Max 2MB) 
    I am lover of this software...

    Link to Download SQLDbx Personal Edition...
    SQLDbx Personal Edition

    I will give more information on SQLDbx with screen shot in later post.
    what is sql server            what is sql server            what is sql server                 what is sql server       software database           software database             software database                 software database            database software           database software             database software                database software      sql tools       sql tools       sql tools       sql tools       tool for sql     tool for sql     tool for sql     tool for sql