{"id":5384,"date":"2013-04-21T00:00:49","date_gmt":"2013-04-21T00:00:49","guid":{"rendered":"http:\/\/craftydba.com\/?p=5384"},"modified":"2017-10-08T16:25:06","modified_gmt":"2017-10-08T16:25:06","slug":"string-functions-soundex","status":"publish","type":"post","link":"https:\/\/craftydba.com\/?p=5384","title":{"rendered":"String Functions &#8211; SOUNDEX()"},"content":{"rendered":"<p><a href=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/04\/turquoise-yarn-md.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignleft size-thumbnail wp-image-5158\" title=\"turquoise-yarn-md\" src=\"https:\/\/craftydba.com\/wp-content\/uploads\/2013\/04\/turquoise-yarn-md-150x150.png\" alt=\"\" width=\"150\" height=\"150\" \/><\/a><br \/>\nI am going to continue my series of very short articles or tidbits on Transaction SQL string functions. I will exploring the SOUNDEX() function today.<\/p>\n<p>The <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms187384.aspx\">SOUNDEX()<\/a> function calculates a four-character code that is based on how the string sounds when spoken.  Please see my prior <a href=\"https:\/\/craftydba.com\/?p=5211\">blog entry<\/a> for a sample use of this function in conjunction with the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms188753.aspx\">DIFFERENCE()<\/a> function.<\/p>\n<p><a href=\"http:\/\/en.wikipedia.org\/wiki\/Soundex\">Soundex<\/a> was developed by Robert C. Russell and Margaret K. Odell and patented in 1918 \/ 1922.  The United States government created a variation named the American Soundex which was used in the 1930s for retrospective analysis of the US censuses from 1890 through 1920.<\/p>\n<p>The system became popular when <a href=\"http:\/\/en.wikipedia.org\/wiki\/Donald_Knuth\">Donald Knuth&#8217;s<\/a> reference it in his book named &#8220;The Art of Computer Programming&#8221;.<\/p>\n<p>The current American Soundex standard is maintained by the National Archives and Records Administration (<a href=\"http:\/\/www.archives.gov\/research\/census\/soundex.html\">NARA<\/a>).<\/p>\n<p>I will not go into the nitty gritty details of the rules for this system.  However, I want to review how the word &#8216;Mongoose&#8217; recieves a soundex code of M522.<\/p>\n<pre class=\"lang:TSQL theme:familiar mark:1,2-3\" title=\"string functions - soundex()\">\r\n-- Get phonetic algorithm code\r\nselect soundex('Mongoose') as word_val\r\n<\/pre>\n<pre class=\"lang:TSQL theme:epicgeeks\" title=\"output\">\r\noutput: \r\n\r\nword_val\r\n----------\r\nM522\r\n<\/pre>\n<\/p>\n<p>The system disregards the letters A, E, I, O, U, H, W, and Y.  A soundex code always starts with the first letter of the word.  It is followed by a three digit number.  Zeros are added at the end if neccessary.<\/p>\n<p>Therefore, &#8216;Mongoose&#8217; becomes &#8216;ngs&#8217;.  Given the lookup table, the number 522 represents this sequence.  Finally, the first letter and number are combined into the code &#8216;M522&#8217;.<\/p>\n<p>In summary, the SOUNDEX() function is a great way to hash words into codes by considering what sounds simular.  Next time, I will be talking about the <a href=\"http:\/\/msdn.microsoft.com\/en-us\/library\/ms187950.aspx\">SPACE()<\/a> function.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I am going to continue my series of very short articles or tidbits on Transaction SQL string functions. I will exploring the SOUNDEX() function today. The SOUNDEX() function calculates a four-character code that is based on how the string sounds when spoken. Please see my prior blog entry for a sample use of this function in conjunction with the DIFFERENCE() function. Soundex was developed by Robert C. Russell and Margaret K. Odell and patented in 1918 \/ 1922. The United States government created a variation named the American Soundex which&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[814],"tags":[31,15,831,815,29],"class_list":["post-5384","post","type-post","status-publish","format-standard","hentry","category-very-short-articles","tag-database-developer","tag-john-f-miner-iii","tag-soundex","tag-string-function","tag-tsql"],"_links":{"self":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/5384","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=5384"}],"version-history":[{"count":0,"href":"https:\/\/craftydba.com\/index.php?rest_route=\/wp\/v2\/posts\/5384\/revisions"}],"wp:attachment":[{"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=5384"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=5384"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/craftydba.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=5384"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}