CREATE FUNCTION earlyTable( 
                      @startTime datetime,@endTime datetime
                )
                RETURNS table
                AS
                RETURN
                (
                    
                  select wrecord.EmpID,wrecord.EmpName,early= case when count(earlyleave ) is null then 0 
else  count(earlyleave ) end
from wrecord
where sysdate between  @startTime and endTime如果count(earlyleave )没有记录的时候,把他设置为0,求问应该怎么修改?

解决方案 »

  1.   

    (1)count(earlyleave )可能为NULL吗
    (2)没有group by 吗
      

  2.   

    case when count(earlyleave ) is null then 0 
    else  count(earlyleave ) end -->isnull(count(earlyleave),0)
      

  3.   

    select wrecord.EmpID,wrecord.EmpName,early= case when count(earlyleave ) is null then 0 
    else  count(earlyleave ) end 
    from wrecord 
    where sysdate between  @startTime and endTime 首先,感觉你这个语句是有问题的1、有count 怎么能没有 group by 呢
    2、在有group by 的前提下,count为0 这种情况是不存在的,至少是1
      

  4.   

    有group by,只是我没写上,就是count(某个字段),如果结果是0的话,是不来记录的,我想要的效果是,如果是0,就显示成
            字段1   字段2      0
      

  5.   

    同意,晕,除非是连接的时候,几个表,而只COUNT()一个表的,COUNT()没有的话是0
      

  6.   

    CREATE FUNCTION earlyTable( 
                          @startTime datetime,@endTime datetime
                    )
                    RETURNS table
                    AS
                    RETURN
                    (
                        
                      select wrecord.EmpID,wrecord.EmpName,early= count(earlyleave )
    from wrecord
    where sysdate between  @startTime and @endTime
     and  earlyleave='Y'
    group by wrecord.EmpID,wrecord.EmpName这个是原来的函数,如果count是0的话,一点记录也显示不出来,我想要的是,如果count是0,就显示
        empID    empName    early
        1           a       0
      

  7.   


    这个是原来的函数,如果count是0的话,一点记录也显示不出来,我想要的是,如果count是0,就显示 
        empID    empName    early 
        1          a      0
    都没有行数,
    EMPID还有值?
      

  8.   

    earlyleave='Y' 
    因为有这条语句,导致我所有的记录全被过滤掉了,所以count不到记录,才会出来空记录的情况,求问有没有人知道怎么解决这个问题?
    出来
        empID    empName    early 
        1          a      0 
    这个结果
      

  9.   


    SELECT ISNULL((SELECT COUNT(*) FROM TB),0)