Payal sathavara
asked on
Search 'Email address' in where clause in SQL
How to search multiple email address in below SQL query.....
------------------
Declare @EmailId varchar (max)
set @EmailId='anuradha.dutta@x yz.com,HEE NA.SANOTRA @xyz.COM'
Declare @String4 varchar (Max)
Set @String4 ='select * from EmailSummary ES
where ES.'+@EmailIdWhere+'
-------------------------- ---------- ---------- ---------- ---------- ---------- ------
------------------
Declare @EmailId varchar (max)
set @EmailId='anuradha.dutta@x
Declare @String4 varchar (Max)
Set @String4 ='select * from EmailSummary ES
where ES.'+@EmailIdWhere+'
--------------------------
ASKER
Declare @EmailId varchar (max)
set @EmailId='anuradha.dutta@x yz.com,HEE NA.SANOTRA @xyz.COM'
Declare @EmailIdWhere varchar (max)
Set @EmailIdWhere=Case when @EmailId='' then 'EMailAddressesTo<>''''' else 'EMailAddressesTo IN ('''+@EmailId+''')' end
Declare @String4 varchar (Max)
Set @String4 ='select * from EmailSummary ES
where ES.'+@EmailIdWhere+'
set @EmailId='anuradha.dutta@x
Declare @EmailIdWhere varchar (max)
Set @EmailIdWhere=Case when @EmailId='' then 'EMailAddressesTo<>''''' else 'EMailAddressesTo IN ('''+@EmailId+''')' end
Declare @String4 varchar (Max)
Set @String4 ='select * from EmailSummary ES
where ES.'+@EmailIdWhere+'
You need to try like below - Split and then join , IN clause will not work here.
--
Declare @EmailId varchar (max) =''
set @EmailId='anuradha.dutta@xyz.com,HEENA.SANOTRA@xyz.COM'
DECLARE @x AS XML=''
SET @x = CAST('<A>'+ REPLACE(@EmailId,',','</A><A>')+ '</A>' AS XML)
SELECT * FROM EmailSummary ES
INNER JOIN
(
SELECT t.value('.', 'VARCHAR(200)') Value FROM @x.nodes('/A') AS x(t)
)p ON p.Value = ES.EMailAddressesTo
--
ASKER
Dear Sir,
I have also search with accountID as well as Email then ?
Declare @AccountMasterId varchar (max)
set @AccountMasterId='495,1211 0'
Declare @AccountMasterIdsWhere varchar (max)
Set @AccountMasterIdsWhere=Cas e when @AccountMasterId='0' then 'AccountMasterId<>-1111' else 'AccountMasterId in ('+@AccountMasterId+')' end
DECLARE @x AS XML=''
SET @x = CAST('<A>'+ REPLACE(@EmailId,',','</A> <A>')+ '</A>' AS XML)
SELECT * FROM #EmailSummary ES LEFT OUTER JOIN AccountMaster A ON A.EMail = ES.EMailAddressesTo
INNER JOIN
(
SELECT t.value('.', 'VARCHAR(200)') Value FROM @x.nodes('/A') AS x(t)
)p ON p.Value = ES.EMailAddressesTo
I have join account master and search with AccountMasterID....How to set in Query ?
I have also search with accountID as well as Email then ?
Declare @AccountMasterId varchar (max)
set @AccountMasterId='495,1211
Declare @AccountMasterIdsWhere varchar (max)
Set @AccountMasterIdsWhere=Cas
DECLARE @x AS XML=''
SET @x = CAST('<A>'+ REPLACE(@EmailId,',','</A>
SELECT * FROM #EmailSummary ES LEFT OUTER JOIN AccountMaster A ON A.EMail = ES.EMailAddressesTo
INNER JOIN
(
SELECT t.value('.', 'VARCHAR(200)') Value FROM @x.nodes('/A') AS x(t)
)p ON p.Value = ES.EMailAddressesTo
I have join account master and search with AccountMasterID....How to set in Query ?
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
What column has email ids?