WHERE句でCASE文を使用しようとしましたが、動作しませんでした。 ご協力いただきありがとうございます!SQL(SQL Server)のWHERE句のCASE文
SELECT
...
FROM ...
WHERE
CASE
WHEN @LastName <> '' AND @CardNo <> '' AND @StoreNo <> '' THEN
((m.ApplicantLastName LIKE @LastName AND m.StoreNo = @StoreNo) OR
(m.CardNo LIKE @CardNo AND LTRIM(RTRIM(m.ApplicantLastName)) <> ''))
WHEN @LastName <> '' AND @CardNo <> '' THEN
(m.ApplicantLastName LIKE @LastName OR (m.CardNo LIKE @CardNo AND LTRIM(RTRIM(m.ApplicantLastName)) <> ''))
WHEN @LastName <> '' AND @StoreNo <> '' THEN
(m.ApplicantLastName LIKE @LastName AND m.StoreNo = @StoreNo)
WHEN @LastName <> '' THEN
m.ApplicantLastName LIKE @LastName
WHEN @CardNo <> '' THEN
(m.CardNo LIKE @CardNo AND LTRIM(RTRIM(m.ApplicantLastName)) <> '')
END