In you situation, I would recommend splitting if it suits you.
Try this query: Let me know if it works for you
DECLARE @email NVARCHAR(222) = 'userA@gmail.com,userB@gmail.com,userC@gmail.com'
DECLARE @Delimiter NCHAR(1) = ','
DECLARE @EmailParam TABLE(email NVARCHAR(222))
;WITH Split(StPos,EndPos)
AS(
SELECT 0 AS StPos, CHARINDEX(@Delimiter,@email) AS EndPos
UNION ALL
SELECT EndPos+1, CHARINDEX(@Delimiter,@email,EndPos+1)
FROM Split
WHERE EndPos > 0
)
INSERT INTO @EmailParam (email)
SELECT SUBSTRING(@email,StPos,COALESCE(NULLIF(EndPos,0),LEN(@email)+1)-StPos) FROM Split
SELECT Users.*
FROM Users
INNER JOIN @EmailParam EmailParam
ON Users.email = EmailParam.email;
Explanation:
I have just extended your query to deal with multiple emails.
As you mentioned if are sure about input format being comma separated string, it might worth trying to derive table variable from it.
So If your input is like:
DECLARE @email NVARCHAR(222) = 'userA@gmail.com,userB@gmail.com,userC@gmail.com'
You can split it using any tsql technique, I have used common table expression here.
Then once you have it in tabular format. I have got it in table variable named @EmailParam
here. You can then easily use add a join and filter it.
if your query works with deterministic encryption, then this query may work in the similar way as only additional change in regard to filer is we have inner join
now. ,