首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >计算列-在关键字'when‘附近的不正确语法

计算列-在关键字'when‘附近的不正确语法
EN

Stack Overflow用户
提问于 2014-01-08 09:38:46
回答 6查看 2.3K关注 0票数 0

我正在尝试向SQLServer2008Express表中添加计算列。

公式是:

代码语言:javascript
复制
case when callrecord_contacttype=1 then 'Routed voice' 
else when callrecord_contacttype=2 then 'Direct incoming voice' 
else when callrecord_contacttype=3 then 'Direct outgoing voice' 
else when callrecord_contacttype=4 then 'Direct internal voice' 
else when callrecord_contacttype=5 then 'Routed callback' 
else when callrecord_contacttype=6 then 'Routed email' 
else when callrecord_contacttype=7 then 'Direct outgoing email' 
else when callrecord_contacttype=8 then 'Routed chat' else '' end

但我发现了错误:

在关键字'when‘附近有错误的语法。

EN

回答 6

Stack Overflow用户

回答已采纳

发布于 2014-01-08 09:41:27

试着:

代码语言:javascript
复制
case callrecord_contacttype
    when 1 then 'Routed voice' 
    when 2 then 'Direct incoming voice' 
    when 3 then 'Direct outgoing voice' 
    when 4 then 'Direct internal voice' 
    when 5 then 'Routed callback' 
    when 6 then 'Routed email' 
    when 7 then 'Direct outgoing email' 
    when 8 then 'Routed chat'
    else ''
end

有关语法,请参见http://msdn.microsoft.com/en-us/library/ms181765.aspx

票数 4
EN

Stack Overflow用户

发布于 2014-01-08 09:41:53

查询中只有一个ELSE

代码语言:javascript
复制
case when callrecord_contacttype=1 then 'Routed voice' 
when callrecord_contacttype=2 then 'Direct incoming voice' 
when callrecord_contacttype=3 then 'Direct outgoing voice' 
when callrecord_contacttype=4 then 'Direct internal voice' 
when callrecord_contacttype=5 then 'Routed callback' 
when callrecord_contacttype=6 then 'Routed email' 
when callrecord_contacttype=7 then 'Direct outgoing email' 
when callrecord_contacttype=8 then 'Routed chat' 
else '' end
票数 3
EN

Stack Overflow用户

发布于 2014-01-08 09:42:05

else只属于最后的非条件子句:

代码语言:javascript
复制
case when callrecord_contacttype=1 then 'Routed voice' 
     when callrecord_contacttype=2 then 'Direct incoming voice' 
     when callrecord_contacttype=3 then 'Direct outgoing voice' 
     when callrecord_contacttype=4 then 'Direct internal voice' 
     when callrecord_contacttype=5 then 'Routed callback' 
     when callrecord_contacttype=6 then 'Routed email' 
     when callrecord_contacttype=7 then 'Direct outgoing email' 
     when callrecord_contacttype=8 then 'Routed chat'
     else '' end
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20991842

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档