select title_id
CASE SUBSTRING(title_id,1,2),
  when 'BU' then 'business'
when 'MC' then 'Modern Cooking'
when 'PC' then 'Popular Computing'
when 'PS' then 'Psychology'
when 'TC' then 'Traditional Cooking'
END AS BookType
from titles
服务器: 消息 156,级别 15,状态 1,行 2
在关键字 'CASE' 附近有语法错误。
也看过了case的具体用法,还是找不出什么问题!帮忙,谢谢啦!

解决方案 »

  1.   

    select title_id, 
    CASE 
    when SUBSTRING(title_id,1,2)='BU' then 'business' 
    when SUBSTRING(title_id,1,2)='MC' then 'Modern Cooking' 
    when SUBSTRING(title_id,1,2)='PC' then 'Popular Computing' 
    when SUBSTRING(title_id,1,2)='PS' then 'Psychology' 
    when SUBSTRING(title_id,1,2)='TC' then 'Traditional Cooking' 
    END AS BookType 
    from titles 
      

  2.   

    select title_id,
    CASE SUBSTRING(title_id,1,2)
    when 'BU' then 'business' 
    when 'MC' then 'Modern Cooking' 
    when 'PC' then 'Popular Computing' 
    when 'PS' then 'Psychology' 
    when 'TC' then 'Traditional Cooking' 
    END AS BookType 
    from titles 
      

  3.   

    select title_id, 
    CASE SUBSTRING(title_id,1,2) 
    when 'BU' then 'business' 
    when 'MC' then 'Modern Cooking' 
    when 'PC' then 'Popular Computing' 
    when 'PS' then 'Psychology' 
    when 'TC' then 'Traditional Cooking' 
    END AS BookType 
    from titles
      

  4.   

    case 和 when 之间不需要,号隔开
      

  5.   

    CASE SUBSTRING(title_id,1,2), 
    帅哥,你最后加一个逗号干嘛???
    CASE ... WHEN ... THEN ... ELSE ... END