Because there is no column on
tblCustomer
called
theField
Sometimes you can get around this by doing something like
Select
Case ISNULL(@aField,'Null')
When 'Null' Then 'Null'
Else 'NotNull'
End as theField,
COUNT(*)
From
tblCustomer
Group By 1
but in this case you will get another error
Quote:
Each GROUP BY expression must contain at least one column that is not an outer reference.
Again because you are trying to use
Group By
with something that does not use columns on the table.
It's not entirely clear what you are trying to do with
@afield