Question

I have the following query:

SELECT 
   'button_flag' = CASE
                      WHEN (can_assign_supervisor = 1 AND (SUM(ISNULL(auto_assign_cap, 0) - ISNULL(assigned_today_cap, 0)) > 0)) 
                      THEN 1
                      ELSE 0
                   END
FROM processor
WHERE prsn_pk = 36381

When I try and run the query I get the error:

Msg 8120, Level 16, State 1, Line 3
Column 'processor.can_assign_supervisor' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.

I am not clear why this error is happening.

  • can_assign_supervisor is a BIT
  • auto_assign_cap and assigned_today_cap are int
  • prsn_pk is the primary key

Any advice?

Thank you

Was it helpful?

Solution

You don't say what you want to do,

this will work

SELECT 
  'button_flag' = SUM(CASE
       WHEN (can_assign_supervisor = 1 AND
             (SUM(ISNULL(auto_assign_cap, 0) - ISNULL(assigned_today_cap, 0)) > 0)
            ) 
       THEN 1
       ELSE 0
       END)
 FROM processor
 GROUP BY prsn_pk, can_assign_superviosor
 WHERE prsn_pk = 36381

as will this:

SELECT 
  'button_flag' = SUM(CASE
       WHEN (can_assign_supervisor = 1 AND
             (ISNULL(auto_assign_cap, 0) - ISNULL(assigned_today_cap, 0)) > 0)
            ) 
       THEN 1
       ELSE 0
       END)
 FROM processor
 WHERE prsn_pk = 36381
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top