select kcbl=case 
          when  isnull(kc,0)<>0  
          then
            case 
               when isnull(xs,0)<>0 then
                     isnull(kc,0)/isnull(xs,0) 
               else
                begin
                   '-'            
                end
             end
          else
           0  
          end
       from t为啥不行?

解决方案 »

  1.   

    select a,(case when v = 0 then '-' else cast(v as varchar) end) as v
    from 表
      

  2.   

    select a,case a when 0 then '-' else a end as v
    from t
      

  3.   

    select a,case when v=0 then convert(varchar(4),'-') 
                  else v end v order by a
      

  4.   

    select a,case when v=0 then convert(varchar(4),'-') 
                  else v end v from table  order by a
      

  5.   

    测试:
    create table t1(a int,v int)
    insert t1 values(1,0)
    insert t1 values(2,3)
    insert t1 values(3,4)
    insert t1 values(4,0)select a,(case when v = 0 then '-' else cast(v as varchar) end) as v
    from t1a           v                              
    ----------- ------------------------------ 
    1           -
    2           3
    3           4
    4           -(所影响的行数为 4 行)
      

  6.   


    这个最好是在前台做显示格式。不要在查询时做。查询语句这样就行:select * from t
      

  7.   

    select id, case cast(应收增加 as varchar(10)) when '0' then '-'
    else cast(应收增加 as varchar(10)) end 
    from test
      

  8.   

    在此贴,偶学会了CASE,做个记号,谢谢~~简单 CASE 函数:CASE input_expression 
        WHEN when_expression THEN result_expression 
            [ ...n ] 
        [ 
            ELSE else_result_expression 
        ] 
    END CASE 搜索函数:CASE
        WHEN Boolean_expression THEN result_expression 
            [ ...n ] 
        [ 
            ELSE else_result_expression 
        ] 
    END