T-SQL reference › TRIM
TRIM, LTRIM and RTRIM in SQL Server
Imports come in with spaces. Two emails that look the same will not GROUP BY together until you trim.
Clean then compare
SELECT LOWER(TRIM(email)) AS email, COUNT(*) AS times
FROM Customers
GROUP BY LOWER(TRIM(email))
HAVING COUNT(*) > 1;
TRIM (2017+) knocks both ends. Older servers: LTRIM(RTRIM(email)). See find duplicates.
Try it on Harbour & Co
Amy Nair (Finance Lead) needs this now: “Mailing list for the newsletter. Some names have stray spaces and emails have capitals. Clean it, no duplicates.” Write the query, run it, send the results. On the paid plan.
Take the ticket →Learn it on a real ticket
Monday is free on WorkSQL. A colleague’s ticket lands, you write the T-SQL, we mark it. No videos. Five minutes.
Clock in free See Monday’s tickets