20.07.2013 Views

Beginning SQL

Beginning SQL

Beginning SQL

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

LastName LOWER(SUBSTRING(LastName,1,1)) + SUBSTRING(LastName,2,LEN(LastName) - 1)<br />

Doors doors<br />

Dales dales<br />

Botts botts<br />

The SOUNDEX() and DIFFERENCE() Functions<br />

So far, all searching and matching with strings have been based on their actual characters. The following<br />

<strong>SQL</strong>, for example, matches only the FirstName Jack:<br />

SELECT FirstName<br />

WHERE FirstName = ‘Jack’;<br />

Sometimes, however, the exact spelling of a name might not be known; you might have only an idea of<br />

what it sounds like. It’s exactly this problem that the SOUNDEX() and DIFFERENCE() functions are<br />

designed to conquer. Unfortunately MS Access doesn’t support SOUNDEX() or DIFFERENCE(). My<strong>SQL</strong>,<br />

on the other hand, supports SOUNDEX() but doesn’t support DIFFERENCE().<br />

The SOUNDEX() function converts a string into a special four-character code representing the way the<br />

string sounds rather than how it is spelled. Its basic syntax is as follows:<br />

SOUNDEX(name_to_be_converted_to_code);<br />

Note that MS Access doesn’t support the SOUNDEX() function.<br />

The first character in the code is always the first character of the original string. Following that is a threedigit<br />

number representing how the word sounds based on the SOUNDEX() guidelines. SOUNDEX() was<br />

actually first developed long before database systems, for use with the U.S. census and patented in 1918.<br />

For example, the following <strong>SQL</strong> returns the SOUNDEX() values for first names in the MemberDetails table:<br />

SELECT FirstName,SOUNDEX(FirstName)<br />

FROM MemberDetails;<br />

The query results are as follows:<br />

FirstName SOUNDEX(FirstName)<br />

Katie K300<br />

Susie S200<br />

Doris D620<br />

Jenny J500<br />

John J500<br />

Jack J200<br />

Manipulating Data<br />

Table continued on following page<br />

175

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!