Sql Server:使用CASE有三个条件

时间:2016-03-11 10:30:11

标签: sql-server-2008

我想在{3}条件中使用CASE。它显示错误。

我的查询:

 select distinct a.phone, other,starttime,duration,imeinumber,
 imsinumber,call_type,a.provider_key, a.celltowerid, siteaddress,
 lat, long, azimuth from cdat a
 left join cdatdupl.dbo.cdatcelltowerareanew b on 
    case 
    when a.provider_key!='9' then a.tower_key=b.tower_key 
    else a.celltowerid = b.celltowerid
        and a.provider_key=b.provider_key 
        and a.state_key end=b.state_key

1 个答案:

答案 0 :(得分:0)

您必须使用CASE关键字

关闭end表达式

<强>语法

CASE { simple_case_expression
     | searched_case_expression
     }
     [ else_clause ]
     END

更新了查询

 select distinct a.phone, other,starttime,duration,imeinumber,
 imsinumber,call_type,a.provider_key, a.celltowerid, siteaddress,
 lat, long, azimuth from cdat a
 left join cdatdupl.dbo.cdatcelltowerareanew b on 
    case 
        when a.provider_key!='9' then a.tower_key=b.tower_key 
        else (a.celltowerid = b.celltowerid
            and a.provider_key=b.provider_key 
            and a.state_key end=b.state_key)
    end