以下の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