下面的 sql 查询适用于 CASE WHEN 中的所有检查,接受某些电子邮件。当我每次运行查询检查电子邮件时,它有时会起作用,有时却不起作用。我已经完成了 RTRIM(LTRIM(m.Email)) 但这也不起作用。比较电子邮件时,我需要做些不同的事情吗?
exec BuildingPros.uspGetEmployees 1697,'Email','someone@somewhere.net'
alter proc BuildingPros.uspGetEmployees
@ProID INT,
@Where VARCHAR(12) = NULL,
@Equals VARCHAR(25) = NULL
AS
SELECT m.UserId,u.UserName,e.NonProID'ID',m.Email,c.FirstName'FName',c.LastName'LName',
ISNULL(c.Title,'NA')'Title',z.ZIPCode'Zip', p.Phone
FROM Person.UtbAddressesutbContact ac JOIN
Person.utbAddresses a ON ac.AddressID = a.AddressID JOIN
Person.utbContact c ON ac.ContactID = c.ContactID JOIN
Person.utbZipCodes z ON z.ZipCodeID = a.ZipCodeID JOIN
Person.utbCitys city ON city.CityID = z.CityID JOIN
Person.utbContactUtbPhones cp ON c.ContactID = cp.ContactID JOIN
Person.utbPhones p ON p.PhoneID = cp.PhonesID JOIN
NonPros.utbNonProsUtbAddresses ea ON a.AddressID = ea.AddressID JOIN
aspnet_Membership m JOIN
NonPros.NonPros e ON m.UserId = e.UserID ON ea.NonProID = e.NonProID JOIN
BuildingPros.utbProfessionalsUtbNonPros pe ON e.NonProID = pe.NonProID JOIN
dbo.aspnet_Users u ON u.UserId = m.UserId
WHERE
CASE @Where
WHEN 'Email' THEN m.Email
WHEN 'Name' THEN c.LastName
WHEN 'Zip' THEN z.ZIPCode
WHEN 'ST' THEN z.StateCD
WHEN 'Title' THEN c.Title
WHEN 'TimeZone' THEN z.TimeZone
WHEN 'City' THEN city.City
END = @Equals