SELECT ISNULL(Result,0) FROM table WHERE MH_Month<='200902'===从表里面查询Result ,如果没有符合条件的记录,就返回0.上述语句不行。返回还是没有记录。我需要一个0,该怎么办?

解决方案 »

  1.   

    declare @t table(Result int ,MH_Month varchar(10))
    insert @t select null,'200101'SELECT ISNULL(Result,0) FROM @t WHERE MH_Month <='200902' 
      

  2.   

    SELECT 
    case when Result is not null then Result else 0 end 
    FROM table WHERE MH_Month <='200902'
      

  3.   


    SELECT COUNT(1) FROM table WHERE MH_Month <='200902' 
      

  4.   


    IF EXISTS(SELECT 1 FROM table WHERE MH_Month <='200902')
     SELECT Result FROM table WHERE MH_Month <='200902'
    ELSE 
     SELECT 0
      

  5.   

    if not exists(select 1 from table WHERE MH_Month <='200902')
       print '0'
    else
       ...
      

  6.   

    问题搞错了,ISNULL可以解决的,不过这个还是按错问题给分了。