不用if
在一句中写出不大于零就等于零
否则保持原值

解决方案 »

  1.   

    case when col < 0 then 0 else col end
      

  2.   

    select case when col=<0 then 0 else col end
      

  3.   

    应该是:
    select case when col<=0 then 0 else col end
      

  4.   

    if object_id('fnIIF') is not null
        drop function fnIIF
    GO
    create function fnIIF(@i int)
    returns int
    as
    begin
        return case when @i <= 0 then 0 else @i end
    end
    GOselect dbo.fnIIF(0),dbo.fnIIF(-9),dbo.fnIIF(9)drop function fnIIF
      

  5.   

    case when col < 0 then 0 else col end
    case when col=<0 then 0 else col end
    这两个没区别