问题是这样的,我们开发的是前辈留下来的项目,以前他们用的是SQLite数据库,其中有个视图的脚本
--职称等级与编制类型视图
CREATE VIEW vbZCBZ
as
  select
  ZCJB,--职称等级
  BZLX,--编制类型
  count(*) as RS--人数
  from
  (
      select
      case when ZCJB is null then '初级以下' else ZCJB end as ZCJB,--职称等级
      case  
           when BZLX like '%合同制%' and SFLX then BZLX||'留校'        
           when BZLX like '%合同制%' and not SFLX then BZLX||'外校'        
           else BZLX        
      end as BZLX--编制类型
      from tbPersons
      join tbBZLX on (tbBZLX.AID=BZLXID)      
  )
  group by ZCJB,BZLX; 
我把它复制到sql2005运行,出现了这样的错误
消息 4145,级别 15,状态 1,过程 vbZCBZ,第 13 行
在应使用条件的上下文(在 'then' 附近)中指定了非布尔类型的表达式。
头疼啊,弄了很久不知道如何解决,请高手指点指点。

解决方案 »

  1.   

    SFLX字段的类型是什么?是否已经改动过
      

  2.   


    CREATE VIEW vbZCBZ
    as
      select
      ZCJB,--职称等级
      BZLX,--编制类型
      count(*) as RS--人数
      from
      (
          select
          case when ZCJB is null then '初级以下' else ZCJB end as ZCJB,--职称等级
          case  
               when BZLX like '%合同制%' and SFLX then BZLX||'留校'        
               when BZLX like '%合同制%' and not SFLX then BZLX||'外校'        
               else BZLX        
          end as BZLX--编制类型
          from tbPersons
          join tbBZLX on (tbBZLX.AID=BZLXID)      
      ) A
      group by ZCJB,BZLX; 
    --加个别名!
      

  3.   

    CREATE VIEW vbZCBZ
    as
      select
      ZCJB,--职称等级
      BZLX,--编制类型
      count(*) as RS--人数
      from
      (
          select
          case when ZCJB is null then '初级以下' else ZCJB end as ZCJB,--职称等级
          case  
               when BZLX like '%合同制%' and SFLX then '留校'        
               when BZLX like '%合同制%' and not SFLX then '外校'        
               else BZLX        
          end as BZLX--编制类型
          from tbPersons
          join tbBZLX on (tbBZLX.AID=BZLXID)      
      ) p
      group by ZCJB,BZLX; 
      

  4.   

     and SFLX then BZLX||'留校'        
     when BZLX like '%合同制%' and not SFLX then BZLX||'外校' 
    什麼語法?
      

  5.   

    CREATE VIEW vbZCBZ
    as
      select
      ZCJB,--职称等级
      BZLX,--编制类型
      count(*) as RS--人数
      from
      (
          select
          case when ZCJB is null then '初级以下' else ZCJB end as ZCJB,--职称等级
          case  
               when BZLX like '%合同制%' and SFLX=1 then BZLX+'留校'        
               when BZLX like '%合同制%' and SFLX=0 then BZLX+'外校'        
               else BZLX        
          end as BZLX--编制类型
          from tbPersons
          join tbBZLX on (tbBZLX.AID=BZLXID)      
      ) aa
      group by ZCJB,BZLX
      

  6.   


    这是一种格式
    select * from (...)t 后面都要加个别名