您好我正在尝试运行此查询,但在where语句中,Case正在发出错误。我要做的是,如果i_id is >= 284
在cnint <=65
之后附加另一个and
,则将Select cnint as Id, cnabbv as Code, rtrim(cnname) as Name, i_id as CId, cntry as CCode
from money.country where cntype = 1 and (CASE
WHEN i_id = 284 THEN cnint <= 65
ELSE cnint > 65
END)
order by cnname;
附加到查询中。此查询位于存储过程中。
{{1}}
此查询位于存储过程中。
答案 0 :(得分:3)
那里不支持。试试这个:
Select cnint as Id, cnabbv as Code, rtrim(cnname) as Name, i_id as CId, cntry as CCode
from money.country where cntype = 1 and
((i_id = 284 AND cnint <= 65) OR (coalesce(i_id, 0) != 284 and cnint > 65))
order by cnname;
答案 1 :(得分:2)
你可以用case
这样的
select cnint as Id,
cnabbv as Code,
rtrim(cnname) as Name,
i_id as CId,
cntry as CCode
from money.country
where cntype = 1 and ( ( i_id = 284 AND cnint <= 65 ) OR (coalesce(i_id, 0) != 284 and cnint>65) )
order by cnname;
当case
返回标量值时,您可以使用case
这样做
但是case
select cnint as Id,
cnabbv as Code,
rtrim(cnname) as Name,
i_id as CId,
cntry as CCode
from money.country
where cntype = 1 AND 1 = (CASE WHEN (i_id = 284 AND cnint <= 65 ) OR (coalesce(i_id, 0) != 284 and cnint >65)
THEN 1
ELSE 0
END)
order by cnname;