Skip to content

Instantly share code, notes, and snippets.

@itspluxstahre
Created August 24, 2023 16:21
Show Gist options
  • Save itspluxstahre/3509f43b47f9449d9ba5b0d76a607626 to your computer and use it in GitHub Desktop.
Save itspluxstahre/3509f43b47f9449d9ba5b0d76a607626 to your computer and use it in GitHub Desktop.
SELECT
[email].[id]
,CASE
WHEN [TED_CI].[email] IS NULL
THEN NULL
WHEN
CHARINDEX(' ',LTRIM(RTRIM([TED_CI].[email]))) = 0
AND LEFT(LTRIM([TED_CI].[email]),1) <> @
AND RIGHT(RTRIM([TED_CI].[email]), 1) <> '.'
AND CHARINDEX('.', [TED_CI].[email] ,CHARINDEX('@',[TED_CI].[email])) - CHARINDEX('@', [TED_CI].[email]) > 1
AND LEN(LTRIM(RTRIM([TED_CI].[email]))) - LEN(REPLACE(LTRIM(RTRIM([TED_CI].[email])),'@','')) = 1
AND CHARINDEX('.',REVERSE(LTRIM((RTRIM([TED_CI].[email]))))) >= 3
AND (CHARINDEX(.@, [TED_CI].[email]) = 0 AND CHARINDEX('..', [TED_CI].[email]) = 0)
AND LEFT([TED_CI].[email], charindex('@', [TED_CI].[email]) -1) NOT LIKE '%[^A-z0-9!#$%&*+\-/=?^_{|}~.]%' ESCAPE '\'
AND RIGHT([TED_CI].[email], LEN([TED_CI].[email]) - charindex('@', [TED_CI].[email])) NOT LIKE '%[^A-Za-z0-9.-]%'
THEN TRIM([TED_CI].[email])
ELSE NULL
END AS [mail]
FROM [dbo].[vTED_contactInfo] [TED_CI]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment