select ISNULL(totaltime.totaltime,0)/ISNULL(totalcount.totalcount,1) 
 from
 (select SUM(DATEDIFF(HOUR,receivedate + ' ' + receivetime,case isnull(operatedate,'')  when '' then  '2012-10-30 23:59:59' else operatedate + ' ' + operatetime end)) as totaltime 
 from View_Workflow_ActOperator as a inner join HrmResource as b on a.userid = b.id inner join workflow_nodebase as c on a.nodeid = c.id where c.isstart = 0 and c.isend = 0 and b.subcompanyid1 = 7
 )as totaltime 
 left join  
 (select count(1) as totalcount 
 from View_Workflow_ActOperator as a inner join HrmResource as b on a.userid = b.id   inner join workflow_nodebase as c on a.nodeid = c.id where c.isstart = 0 and c.isend = 0 and b.subcompanyid1 = 7
) as totalcount总是在最后一个totalcount后面显示红色波浪线

解决方案 »

  1.   

    SELECT  ISNULL(( SELECT SUM(DATEDIFF(HOUR, receivedate + ' ' + receivetime,
                                         CASE ISNULL(operatedate, '')
                                           WHEN '' THEN '2012-10-30 23:59:59'
                                           ELSE operatedate + ' ' + operatetime
                                         END)) AS totaltime
                     FROM   View_Workflow_ActOperator AS a
                            INNER JOIN HrmResource AS b ON a.userid = b.id
                            INNER JOIN workflow_nodebase AS c ON a.nodeid = c.id
                     WHERE  c.isstart = 0
                            AND c.isend = 0
                            AND b.subcompanyid1 = 7
                   ), 0)
            / ISNULL(( SELECT   COUNT(1) AS totalcount
                       FROM     View_Workflow_ActOperator AS a
                                INNER JOIN HrmResource AS b ON a.userid = b.id
                                INNER JOIN workflow_nodebase AS c ON a.nodeid = c.id
                       WHERE    c.isstart = 0
                                AND c.isend = 0
                                AND b.subcompanyid1 = 7
                     ), 1)