4

我正在检查很多存在类似错误的问题,但找不到可以帮助我解决我选择的错误的问题

select 
    case 
    when e.EthnCode in ('N','A','B','P','W') then ethnicity
    else 'Multi' 
    end as Ethnicity,
    case when cat.CategCode IN ('CH','IN','NB','PG','PP','SR')then Category else 0 end as ' ',
 --COUNT (c.EthnCode) as '(A) tottal Numbers of participamts by Rase', 
 sum(case when C.StatusID =1 or C.StatusID =2 then 1 else 0 end),
 sum(case when c.Hispanic then 1 else 0 end) as 'Hisp'
from  Ethnicity E
LEFT JOIN Clients C
ON c.EthnCode = e.EthnCode 
LEFT join Category cat 
ON c.CategCode = cat.CategCode
where c.StatusID = 1 
group by case 
    when e.EthnCode in ('N','A','B','P','W') then ethnicity
    else 'Balance Reporting More Than One Race' 
    end

它抛出错误

Msg 4145, Level 15, State 1, Line 9
An expression of non-boolean type specified in a context where a condition is expected, near 'then'.

9号线

 sum(case when c.Hispanic then 1 else 0 end) as 'Hisp'

它强调西班牙裔请需要帮助:)

4

2 回答 2

3
 sum(case when c.Hispanic then 1 else 0 end) as 'Hisp'

更改为(请在比较中使用正确的值和数据类型)

 sum(case when c.Hispanic = 1 then 1 else 0 end) as 'Hisp'

或者对于一个简单的案例

 sum(case c.Hispanic when 1 then 1 else 0 end) as 'Hisp'
于 2013-02-25T23:50:01.643 回答
1

它不认为 C.Hispani 是布尔值。 Case When C.Hispanic = 1 Then……

或者一些这样的人会解决它。

于 2013-02-25T23:50:29.487 回答