SELECT CHARINDEX(RTRIM(B.Words), U.url), *FROM #urltbl U CROSS JOIN #Badwords AS BWHERE CHARINDEX(RTRIM(B.Words), U.url) <> 0ORDER BY username, url
SELECT CHARINDEX(RTRIM(B.Words), U.url), *FROM #urltbl U CROSS JOIN #Badwords AS BWHERE MSGDATE >= '12/10/2010' AND /* using the next day because if you want all of 1/1 and there are any times included you need to do less than the next day */ MSGDATE < '1/2/2011' AND CHARINDEX(RTRIM(B.Words), U.url) <> 0ORDER BY username, url