本帖最后由 cowbobe 于 2013-10-28 11:57:52 编辑

解决方案 »

  1.   

    试试:select AppNo,ClientName,
    (select case when isnull(AppNo,'')<>'' then '已执行' else '未执行' end from OPA where appno=apply.appno) as '流程A',
    (select case when isnull(AppNo,'')<>'' then '已执行' else '未执行' end from OPB where appno=apply.appno) as '流程B'
     from apply
      

  2.   

    select AppNo,ClientName,
    (select case when  AppNo  isnull then '已执行' else '未执行' end from OPA where appno=apply.appno) as '流程A',
    (select case when AppNo isnull  then '已执行' else '未执行' end from OPB where appno=apply.appno) as '流程B'
     from apply
    is null 和<>'' 是有很大的区别的,你用这两种情况多试下结果就会发现的 
      

  3.   

    楼上的兄弟不行啊,如果是ELSE的情况,还是显示NULL,它就不显示那个"未执行"
      

  4.   


    select a.AppNo,a.ClientName,case when ISNULL(b.appno,'')<>'' then '已执行' else '未执行' end as '流程A',
                                case when ISNULL(c.appno,'')<>'' then '已执行' else '未执行' end as '流程B',
     from apply a left join opa b on a.appno=b.appno
                  left join opb c on a.appno=c.appno 
      

  5.   

    修正楼上最后多了个,号select a.AppNo,a.ClientName,case when ISNULL(b.appno,'')<>'' then '已执行' else '未执行' end as '流程A',
                                case when ISNULL(c.appno,'')<>'' then '已执行' else '未执行' end as '流程B'
     from apply a left join opa b on a.appno=b.appno
                  left join opb c on a.appno=c.appno 
      

  6.   

    改成这样试试看:
    select AppNo,ClientName,
    (select case when isnull(AppNo,'')<>'' then '已执行' else '未执行' end from OPA where appno=apply.appno) as '流程A',
    (select case when isnull(AppNo,'')<>'' then '已执行' else '未执行' end from OPB where appno=apply.appno) as '流程B'
     from apply
      

  7.   

    有可能,你的两边的数据库里的表,不一定相同,可能会有null值,导致两边不同
      

  8.   


    select AppNo,ClientName,
    (select case when AppNo<>'' then '已执行' else '未执行' end from OPA where appno=apply.appno) as '流程A',
    (select case when AppNo<>'' then '已执行' else '未执行' end from OPB where appno=apply.appno) as '流程B'
     from apply--你的NULL值没处理
      

  9.   

    用了7楼的方法是可以的,但是我还有很多case when 总不是一个个join吧...
    什么原因呢?
      

  10.   

    select * from OPA where appno is null
    select * from OPb where appno is null看看是不是有数据
      

  11.   


    select AppNo,ClientName,
    case when (select  AppNo from OPA where appno=apply.appno)<>'' then '已执行' else '未执行' end as '流程A',
    case when (select AppNo from OPB where appno=apply.appno)<>'' then '已执行' else '未执行' end as '流程B'
     from apply标准的写法还是7L的好
      

  12.   

    把case when写成一个函数就好了。
      

  13.   

    嘎嘎,加个ISNULL(AppNo,'')...1楼已经加了
      

  14.   

    SQL2000 打 SP4 补丁了没有
    SELECT SERVERPROPERTY('productversion'), SERVERPROPERTY('productlevel'),SERVERPROPERTY ('edition')
    结果如下:
    SQLServer2000    SP4   8.00.2039
      

  15.   

    嘎嘎,加个ISNULL(AppNo,'')...1楼已经加了
    目测不出原因,呵呵.但是我感觉这样写好怪啊··一般我是用Join的...不用这种写法
      

  16.   

    这样呢select AppNo,ClientName,isnull('lca','未执行') as '流程A',isnull('lcb','未执行') AS '流程B'
     from
    (select AppNo,ClientName,
    (select case when isnull(AppNo,'')<>'' then '已执行' else '未执行' end from OPA where appno=apply.appno) as lca,
    (select case when isnull(AppNo,'')<>'' then '已执行' else '未执行' end from OPB where appno=apply.appno) as lcb 
     from apply) a
      
      

  17.   

    你那样的写法 必然会存在null值   
    如果必须要按照你的写法来,那就要想办法去掉null值了
      

  18.   

    按照你的写法 除非 你的流程全部都执行完毕了 才会不存在 null值