select sum(case 上午出勤情况 when '出勤' then 1 else 0)+sum( case 下午出勤情况 when '出勤' then 1 else 0)from 表 where 姓名='某某1' and datepart(month,日期)=7

解决方案 »

  1.   

    Declare @Count intSelect @Count = count(上午出勤情况), 姓名 From 表
    Where 日期 >= 2004-7-1 And 日期 <= 2004-7-31 
         And 上午出勤情况 = '出勤' And 姓名='某某1'
    Group by 姓名Select @Count = @Count + count(下午出勤情况), 姓名 From 表
    Where 日期 >= 2004-7-1 And 日期 <= 2004-7-31 
       And 下午出勤情况 = '出勤' And 姓名='某某1'
    Group by 姓名
      

  2.   

    Declare @Count intSelect @Count = count(上午出勤情况) From 表 
    Where 日期 >= '2004-7-1' And 日期 <= '2004-7-31' And 上午出勤情况 = '出勤' And 
          姓名='某某1'Select @Count = @Count + count(下午出勤情况) From 表
    Where 日期 >= '2004-7-1' And 日期 <= '2004-7-31' And 下午出勤情况 = '出勤' And 
          姓名='某某1'