我已经形成了一个SQL查询来检查电子邮件字段中的值是否为空,并且是否有效,所以如果假设该列中的值为空,那么 它会返回正确的值,但如果该值的格式不正确,则不会返回noproperformat@format.com。因此,如果值是test@test.com.in,则该格式无效,任何人都可以帮助进行此查询。
select Case
when idfEmail!='' then idfEmail
when (idfEmail LIKE '%_@__%.__%.__'
AND PATINDEX('%[^a-z,0-9,@,.,_,\-]%', idfEmail) = 0) then 'noproperformat@format.com'
else('noemailfound@noemail.com') end as idfEmail from mytable order by idfEmail Desc
当我在查询下面运行时,我会收到所有无效的电子邮件。
SELECT idfEmail
FROM wp.APAddress
WHERE idfEmail LIKE '%_@__%.__%.__'
AND PATINDEX('%[^a-z,0-9,@,.,_,\-]%', idfEmail) = 0
答案 0 :(得分:0)
select Case
when (idfEmail!='' and idfEmail Not LIKE '%_@__%.__%.__' ) then idfEmail
when (idfEmail LIKE '%_@__%.__%.__'
AND PATINDEX('%[^a-z,0-9,@,.,_,\-]%', idfEmail) = 0) then 'noproperformat@format.com'
else('noemailfound@noemail.com') end as idfEmail from mytable order by idfEmail Desc
答案 1 :(得分:0)
这是您想要的吗?
select (case when idfEmail like '%[^a-z,0-9,@,.,_,\-]%'
then 'noproperformat@format.com'
when idfEmail is not null
then idfEmail
else 'noemailfound@noemail.com'
end) as idfEmail
from mytable
order by idfEmail desc;
一个case
表达式按顺序评估条件。您的第一个条件基本上与所有非NULL电子邮件匹配,因此返回第一个条件。