I'm attempting to use a case statement, dependent on a variable, to determine part of my WHERE clause, but it doesn't like what I'm doing. Here's my query (modified for simplicity)
DECLARE @SalesType VARCHAR(10)
SET @SalesType = 'Bulk'
SELECT CASE
WHEN fwsf.Customer_Cardlock_Customer = 'True'
THEN 'CFN'
ELSE 'Bulk'
END AS 'Prod Type'
FROM TABLE t
WHERE CASE
WHEN @SalesType = 'Bulk' then t.customer_type = 'False'
WHEN @SalesType = 'CFN' then t.customer_type = 'True'
End
Put another way, I want to state in the WHERE clause that when the @SalesType is a given value, to select the rows that have another value.
EDIT:For sake of others, I realized I had another scenario where I may need to select an 'All' option. Per Shawn below, he corrected my original proposed solution with the following that I verified works:
AND t.customer_type =
CASE @SalesType
WHEN 'Bulk' then 'False'
WHEN 'CFN' then 'True'
WHEN 'All' then t.customer_type
END
END