我试图弄清楚如何验证所有电子邮件中的第一个字母以's'开头,如果不修复它。这是脚本的2 case语句不工作!我可以看看电子邮件地址的第一个字母是否正确。如果电子邮件的开头字母是"s",那就是匹配的,如果开头字母不是's'不匹配
Select
p.personID,
p.studentNumber,
c.email,
SUBSTRING(c.email, 2, CHARINDEX('@',c.email) - 2) StudentNumberFromEmail,
substring(c.email,1, 1) SfromEmail,
-- find missing email and check to see if studentNumber in email is correct
case when p.studentNumber <> SUBSTRING(c.email, 2, CHARINDEX('@',c.email) - 2)
then 'mismatched'
when SUBSTRING(c.email, 2, CHARINDEX('@',c.email)-2) is null
then 'email missing'
else 'matched' end,
-- does the email start with 's'
CONCAT('s',p.studentNumber,'@myemail.org') 'email fixed',
case when c.email <> SUBSTRING(c.email, 1, 1)
then 'mismatched'
when SUBSTRING(c.email, 1,1) is null
then 'email missing'
else 'matched' end
from Person p
join Enrollment e on e.personID = p.personID
and e.endDate is Null and e.serviceType = 'P'
join calendar cal on cal.calendarID = e.calendarID
join SchoolYear sy on sy.endYear = e.endYear and sy.active = 1
join Contact c on c.personID = p.personID
我弄清楚了,我拿出第二个case语句并添加到where子句或子字符串(ct.email,1,1) <>"年代">