You have a computer that has Microsoft SQL Server 2012 installed.
You have a query that contains a CASE statement in a SELECT statement and a CASE statement in a GROUP BY statement.
The two CASE statements evaluate to NULL.
You run the query.
In this scenario, you receive the following error message:
Msg 8120, Level 16, State 1, Line 3
Column '<column name>' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.
For example, you run the following query:
create database testgouse testgocreate table tvt ( v1t binary(1) null)create table tln (ln numeric(5) not null)goselectcase when 1=2 then t1.col1else 10end,casewhen t1.col1 = 2 then t1.col2endfrom (select t2.v1t as col1, 10 as col2 from tvt t2) t1group by case when 1=2 then t1.col1else 10end,casewhen t1.col1 = 2 then t1.col2endgo
In the query, the statement "when 1=2 then t1.col1 else 10" evaluates to 10. When you replace "10" by using NULL, this issue occurs. Note This issue does not occur when you remove either of the CASE statements from the SELECT statement or from the GROUP BY statement.
After you apply the fix, you have to enable a trace flag to make the hotfix work. Please contact Microsoft support when you need to apply this fix.The issue was first fixed in the following cumulative update of SQL Server.
Each new cumulative update for SQL Server contains all the hotfixes and all the security fixes that were included with the previous cumulative update. Check out the latest cumulative updates for SQL Server: