CASE is used with values, you are attempting to use CASE to build part of a statement. You could go the whole hog and perform the latter successfully using dynamic SQL like this:
DECLARE @StringToExecute VARCHAR(MAX), @FilterOption VARCHAR(20), @AccountFilter VARCHAR(20)
SET @FilterOption = 'individual'
SET @AccountFilter = '000012'
SET @StringToExecute =
FROM Customer AS c
WHERE ' +
WHEN 'by group' THEN 'c.AccountNumber LIKE ''AW' + @AccountFilter + '%'''
WHEN 'individual' THEN 'c.AccountNumber = ''' + @AccountFilter + ''''
ELSE '1 = 1'
As Drew has shown there are alternatives which may or may not be better for this case. Check out this recent article for some handy hints on conditional WHERE processing:
[font="Arial"]“Write the query the simplest way. If through testing it becomes clear that the performance is inadequate, consider alternative query forms.” - Gail Shaw[/font]
For fast, accurate and documented assistance in answering your questions, please read this article
Understanding and using APPLY, (I)[/url] and
(II)[/url] Paul White
Hidden RBAR: Triangular Joins[/url] /
The "Numbers" or "Tally" Table: What it is and how it replaces a loop[/url] Jeff Moden