Declarar variable

Aparece un post de error:

Msg 164, nivel 15, estado 1, línea 18
Cada expresión GROUP BY debe contener al less una columna que no sea una reference externa

de este código T-SQL:

 DECLARE @CLIENT_COUNT INT SELECT @CLIENT_COUNT = COUNT(CLT_NBR) FROM CLIENT SELECT CASE WHEN STATUS = 3 THEN 'CATEGORY1' ELSE 'CATEGORY2' END AS Category, COUNT(*) AS COUNT, @CLIENT_COUNT as [Total CLIENT], COUNT(*) / @CLIENT_COUNT as PERCENTAGE FROM CLIENT_STATUS WHERE STATUS IN (3, 8) GROUP BY STATUS, @CLIENT_COUNT 

¿Me puedes ayudar a solucionarlo?

¡Gracias!

Tu syntax es incorrecta Debe colocar todos los valores que deben devolverse antes de FROM .

 DECLARE @CLIENT_COUNT INT SELECT @CLIENT_COUNT = COUNT(CLT_NBR) FROM CLIENT SELECT CASE WHEN STATUS = 3 THEN 'CATEGORY1' ELSE 'CATEGORY2' END AS Category , COUNT(STATUS) AS StatusCount , @CLIENT_COUNT AS [Total CLIENT] , COUNT(STATUS) / @CLIENT_COUNT AS PERCENTAGE FROM CLIENT_STATUS WHERE STATUS IN ( 3 ,8 ) GROUP BY STATUS