Friday, March 25, 2016

Get all unique email domain names from Microsoft Dynamics CRM database

SELECT  COUNT(*), MIN(ISNULL([ParentCustomerIdName], '')),
SUBSTRING(EmailAddress1, CHARINDEX('@', EmailAddress1) + 1, LEN(EmailAddress1) - CHARINDEX('@', EMailAddress1))
  FROM [YourCRMDatabase].[dbo].[Contact]
  WHERE EmailAddress1 IS NOT NULL
  GROUP BY SUBSTRING(EmailAddress1, CHARINDEX('@', EmailAddress1) + 1, LEN(EmailAddress1) - CHARINDEX('@', EMailAddress1))
  ORDER BY COUNT(*) DESC

No comments:

Post a Comment

There was an error in this gadget