sql - Declare variable -


i error message:

msg 164, level 15, state 1, line 18
each group by expression must contain @ least 1 column not outer reference

from t-sql code:

declare @client_count int  select @client_count = count(clt_nbr) client  select      case         when status = 3            'category1'            else 'category2'      end category,     count(*) count,     @client_count [total client],     count(*) / @client_count percentage      client_status      status in (3, 8) group      status, @client_count  

can me fix it?

thank you!

your syntax wrong. need put of values need returned before from.

declare @client_count int  select @client_count = count(clt_nbr) client  select case      when status = 3         'category1'     else 'category2'     end category      , count(status) statuscount      , @client_count [total client]      , count(status) / @client_count percentage client_status status in (        3       ,8     ) group status 

Comments

Popular posts from this blog

java - nested exception is org.hibernate.exception.SQLGrammarException: could not extract ResultSet Hibernate+SpringMVC -

sql - Postgresql tables exists, but getting "relation does not exist" when querying -

asp.net mvc - breakpoint on javascript in CSHTML? -