I want to fetch email addresses from the table which ends with below domain names.
@yahoomail.com
@accelerator.com
@learning.com
@cloud.vintage.com
I want to fetch email addresses from the table which ends with below domain names.
@yahoomail.com
@accelerator.com
@learning.com
@cloud.vintage.com
SELECT EMAIL_COLUMN_NAME
FROM TABLE_NAME
WHERE EMAIL_COLUMN_NAME LIKE '%@yahoomail.com' OR
EMAIL_COLUMN_NAME LIKE '%@accelerator.com' OR
EMAIL_COLUMN_NAME LIKE '%@learning.com' OR
EMAIL_COLUMN_NAME LIKE '%@cloud.vintage.com'
rileyeaton_s answer is correct but I would like to add a recommendation. If your plan is to do this search multiple times and want to improve the performance, you can add a persisted computed column that contains only the domain.
In the following code I have added a computed column that extracts the domain (including @) and also adds an index on that column.
DECLARE @test TABLE (
Email nvarchar(255),
Domain AS SUBSTRING(Email, CHARINDEX('@', Email), 255) PERSISTED,
INDEX IX_Domain (Domain))
INSERT INTO @test VALUES ('abc@123.com')
SELECT * FROM @test WHERE Domain = '@123.com'
This query will give the result:
Email Domain
abc@123.com @123.com