Peter
Peter

Reputation: 11920

Using replace in T-SQL where condition does not seem to work

Environment: SQL Server 2017

Here is a working T-SQL query:

SELECT replace(email, '.', '') as EMAIL
FROM usermaster
WHERE email = '[email protected]'

When executed, this query returns [email protected] as expected.

For my needs, I have to ignore dots when comparing email. Here is the query that I want:

SELECT email
FROM usermaster
WHERE replace(email, '.', '') = '[email protected]'

However, this query does not return me any records. As is obvious from the previous query, I should be getting [email protected] as my output. What is it that I am missing? Regards.

Upvotes: 1

Views: 28

Answers (1)

John Cappelletti
John Cappelletti

Reputation: 81990

Are you sure you're getting the .COM in your first query?

SELECT email
FROM usermaster
WHERE replace(email, '.', '') = 'abcdef@gmailcom'  -- notice no .com

Upvotes: 4

Related Questions