20 pts.
 Substring Query SQL
Hi All, I'm trying to build a query to join names in one table to abbreviated names in another table. So for example I have - Harry Harold Harrison on one table, but in the other table I have just Har, this can vary in length so does anyone know how I can sum the amount of Har names with the total from the other table bearing in mind the data could be Fred for frederick, freddy etc, Kind Regards, Stuart Mills

Software/Hardware used:
ASKED: March 30, 2010  12:44 AM
UPDATED: March 30, 2010  1:53 PM

Answer Wiki:
I figured this out in the end, something like - SELECT SUBSTRING(a.name, 1, LEN(b.NamePrefix)) AS Expr1, COUNT(a.name) AS Expr2, b.NamePrefix FROM Customers a INNER JOIN NamePrefixes b ON b.NamePrefix = SUBSTRING(a.name, 1, LEN(b.NamePrefix)) Gives me a count of names beginning with the matches in the nameprefixes table. So if nameprefixes table has fred in it and names contains Fred, Frederick, Freddy, I get Fred and 3 as the count. Thanks for showing an interest anyway
Last Wiki Answer Submitted:  March 30, 2010  1:53 pm  by  Smillsie   20 pts.
All Answer Wiki Contributors:  Smillsie   20 pts.
To see all answers submitted to the Answer Wiki: View Answer History.


Discuss This Question:
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _


 

Could you provide some example data and the results you would want to get ?

 63,535 pts.