DROP TABLE UsersToDelete
CREATE TABLE UsersToDelete
(
id INT IDENTITY
,email VARCHAR(500)
)
INSERT INTO UsersToDelete
(
-- id -- this column value is auto-generated
email
)
SELECT 'test@yahoo.com''@countag%and1=1''' AS email
UNION
SELECT 'bill.gates@microsoft.com'
UNION
SELECT 'user2675939@stackoverflow.com'
UNION
SELECT 'iamkarlson''''''@google.com'
SELECT utd.id
,utd.email
,CASE
WHEN (SUBSTRING(email ,CHARINDEX('''' ,email ,0) +1 ,1) <>''''
OR SUBSTRING(REVERSE(email) ,CHARINDEX('''' ,REVERSE(email) ,0) +1 ,1) <>'''')
AND email LIKE '%''%'
THEN 1
WHEN SUBSTRING(email ,CHARINDEX('''' ,email ,0) +1 ,1) =''''
AND SUBSTRING(REVERSE(email) ,CHARINDEX('''' ,REVERSE(email) ,0) +1 ,1) =''''
AND email LIKE '%''%'
THEN 0
ELSE 0
END AS [Contains]
,SUBSTRING(email ,CHARINDEX('''' ,email ,0) +1 ,1)
,SUBSTRING(REVERSE(email) ,CHARINDEX('''' ,REVERSE(email) ,0) +1 ,1)
FROM UsersToDelete utd