Sql server operators multiple email addresses
In SQL Server, you can use the LIKE
operator to search for multiple email addresses in a column. Here are a few examples:
Example 1: Search for multiple email addresses using LIKE
SELECT *
FROM table_name
WHERE email_column LIKE '%@example.com|%@another.com';
This will return all rows where the email_column
contains either @example.com
or @another.com
.
Example 2: Search for multiple email addresses using LIKE
with wildcards
SELECT *
FROM table_name
WHERE email_column LIKE '%@example.com|%@another.com|%@yetanother.com';
This will return all rows where the email_column
contains any of the specified email addresses.
Example 3: Search for multiple email addresses using IN
operator
SELECT *
FROM table_name
WHERE email_column IN ('[email protected]', '[email protected]', '[email protected]');
This will return all rows where the email_column
matches any of the specified email addresses.
Example 4: Search for multiple email addresses using OR
operator
SELECT *
FROM table_name
WHERE email_column = '[email protected]' OR email_column = '[email protected]' OR email_column = '[email protected]';
This will return all rows where the email_column
matches any of the specified email addresses.
Example 5: Search for multiple email addresses using a table-valued parameter
CREATE TYPE EmailList AS TABLE (email nvarchar(255));
DECLARE @email_list EmailList;
INSERT INTO @email_list (email)
VALUES ('[email protected]'), ('[email protected]'), ('[email protected]');
SELECT *
FROM table_name
WHERE email_column IN (SELECT email FROM @email_list);
This will return all rows where the email_column
matches any of the email addresses in the @email_list
table-valued parameter.
Note that these examples assume that the email addresses are stored in a column of type nvarchar
or varchar
. If your email addresses are stored in a column of type uniqueidentifier
(e.g., uuid
), you may need to use a different approach.