Re: Each GROUP BY expression must contain at least one column that is not an outer reference

Vic (vikrantp@xxxxxxxxx) writes:
([02-RecordAction]= 'New') AND ('['+@FieldName+'] IS NOT NULL') )
some commented code but basically I am trying to get the total number
of rows (ValidCount) and (NullCount) seperately and use that in the
3rd select statement but it gives me an error saying 'An expression of
non-boolean type specified in a context where a condition is expected,
near ')'. Which is @FieldName in the select statement. Am I doing
anything wrong here?

You have

AND (string-expression)

where the string expression is

'[' + @FieldName + '] IS NOT NULL'

and that does not make much sense at all.

Maybe you like to believe that SQL Server will guess that it should
substitute the value in @FieldName with a column name, but that did
not happen last week, and it is not going to happen this week either.

Generally: if you want to use dynaimc table and column names, you will
need to use dynamic SQL, and it is going to be very painful.

Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx

Books Online for SQL Server 2005 at
Books Online for SQL Server 2000 at