Re: Each GROUP BY expression must contain at least one column that isnot an outer reference On Mar 4, 2:47 pm, Erland Sommarskog <esq...@sommarskog.se> wrote:
> Vic (vikra...@gmail.com) 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, esq...@sommarskog.se
>
> Books Online for SQL Server 2005 athttp://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books...
> Books Online for SQL Server 2000 athttp://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
Hi Erland,
I actually posted and it and right after that I realized that. I got
it working actually with dynamic sql using sp_executesql. Thanks
anyways and sorry for the spam |