I have a process that creates a list of possible duplicate companies. The problem is that "The ABC Company, Inc." and "ABC Company, Inc." both in Dallas, TX are probably duplicates but I won't find them with my criteria. I've eliminated the first 4 characters if they are "the " but I also need to check for the right 5 characters if they are " Inc.".
I have a view that creates a column thename. The prefix "the " has been stripped;
    SELECT     CASE WHEN LEFT(name, 4) = 'The ' THEN RIGHT(name, (len(name) - 4)) ELSE name END AS thename, CASE WHEN CHARINDEX(' ', ltrim(rtrim(Name))) 
                          = 0 THEN ltrim(Name) WHEN CHARINDEX(' ', ltrim(Name)) = 1 THEN ltrim('b') ELSE SUBSTRING(ltrim(Name) + ' x', 1, CHARINDEX(' ', ltrim(Name))) END AS subname, 
                          CHARINDEX(' ', LTRIM(Name)) AS wordcheck, Name, Address_Line_1, City AS Company_City, State AS Company_State, Zip, Area_Code, Phone, Status_Flag, ID, 
                          Not_Dupe_Flag, DUNS, Temp_Check_Dupes_Flag, Parent_Company_Number, Special_Display, 
                          CASE WHEN c.parent_company_number = 0 THEN c.id ELSE c.parent_company_number END AS parent
    FROM         dbo.Companies AS c
Then I use that view in my query to look for duplicates;
        <cfquery name="qResults" datasource="#request.dsnlive#" timeout="200">
            SELECT b.ID,
            Thename,
            substring(TheName,1,(CHARINDEX(' ',TheNAME,1))) as subName,
            name,
            b.address_line_1,
            b.zip,
            b.company_state,
            b.company_city,
            b.area_code,
            b.phone,
            b.Special_Display,
            isnull(not_dupe_flag,'False') as not_dupe_flag,
            isnull(Temp_Check_Dupes_Flag,'False') as Temp_Check_Dupes_Flag,
            b.id as bID,
            b.duns
            FROM dbo.vw_Comp_Details_withFirstWord as b
            WHERE isnull(b.status_flag,'') != 'D'
            and b.ID <> #arguments.CompNum#
                and isnull(b.Temp_Check_Dupes_Flag,'False') = 'False'
            <cfif arguments.IncludeDunsOnly eq 0>
                <cfif arguments.FirstWord>
                    AND b.subName = '#arguments.CompanySubName#'
                <cfelse>
                    AND (substring(dbo.KeepAlphaNumCharacters(Thename),1,#val(arguments.WordLength)#) = substring('#arguments.CompanyName#',1,#val(arguments.WordLength)#)
                    or differnce(soundex(Thename),soundex('#arguments.CompanyName#')) > 2)
                </cfif>
                AND (
                ( company_city = '#arguments.City#'
                 AND Isnull(company_city, '') > '' )
                 AND ( b.parent != #val(arguments.Parent)#
                     AND Isnull(b.parent, '0') > 0 )
                     )
                <cfif arguments.IncludeDuns>
                AND (
                ( REPLACE(LTRIM(REPLACE(b.duns, '0', ' ')), ' ', '0') = '#val(arguments.Duns)#'
                 AND REPLACE(LTRIM(REPLACE(b.duns, '0', ' ')), ' ', '0') > ' '
                 AND #val(arguments.Duns)# > 0 )
                    or  REPLACE(LTRIM(REPLACE(b.duns, '0', ' ')), ' ', '0') = ' '
                    )
                </cfif>
            <cfelse>
                and (REPLACE(LTRIM(REPLACE(b.duns, '0', ' ')), ' ', '0') = '#val(arguments.Duns)#')
            </cfif>
        </cfquery>
Now I need to add code to strip the suffix " Inc." but I can't seem to come up with the logic to end up with a column that contains the name without the prefix "The " and the suffix " Inc."
 
     
     
     
    