I had to do some basic analysis of email addresses at my company the other day.¬ Here are a few useful SQL queries.
Show 10 records with the most data in field ’email’ (10 longest email addresses)
SELECT TOP 10 email, LEN(email) AS fieldLength
FROM person
ORDER BY fieldLength DESC
Count all records with field ’email’ over 20 chars
SELECT COUNT(*) AS emailOver20
FROM person
WHERE LEN(email) > 20
Display the average length of data (in characters) of field ’email’
SELECT AVG(LEN(email)) AS emailAvgLength
FROM person