- 一个月的补卡次数不超过三次(即统计一个月内某人的补卡次数)
表结构是某人一天内的四次打卡状态,这样是统计当月补卡的天数了(错误)
select count(*) from [Proc_HR_Punch]where Account=@account TaskState='approved' and (state='补卡' or state1='补卡' or state2='补卡' or state3='补卡') and
convert(varchar(7),Yeaterdaydate,120)=convert(varchar(7),@date,120)解决方案:把行转为列即可
with M as(
select Account,ISbk,statue,date from[Proc_HR_PunchException]
unpivot(ISbk for statue in (state,state1,state2,state3))a where a.ISbk='补卡'
and Account=@Account and TaskState='approved' and convert(varchar(7),date,120)=convert(varchar(7),@date,120))
select Count(*)from M - 存储过程里使用视图并 对查询结果再次过滤查询
标签:Account,varchar,记录,解决方案,补卡,convert,sqlserver,120,date From: https://www.cnblogs.com/nowlt/p/16998747.html