where后面加判断

get_D get_D 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
select [AttendanceCollectId]=newid()
,[MachineId]=[Machine].MachineId
,[MachineCode]=cardinfo.clockid
,[CardId]=[Card].CardId
,[CardCode]=[Card].CardNo
,[EmployeeName]=[Employee].CnName
,[EmployeeCode]=[Employee].Code
,[EmployeeId]=[Employee].EmployeeId
,[ownerId]=[Employee].EmployeeId
,[DepartmentName]=[Department].Name
,[DepartmentId]=[Department].DepartmentId
,[Date] = cardinfo.date+' '+cardinfo.time
,[Time] = cardinfo.time
,[IsManual] = 0
,[Flag] = '1'
,ApproveResultId='OperatorResult_001'
,StateId ='PlanState_003'
,IsForAttendance='1'
--,AttendanceCollectLogId=@AttCollectLogId
from
(select * from (
select right(CONVERT(varchar(16),DATEADD(ss,a.KqTime, cast('00:00:00' AS datetime)), 121),5) time,
CONVERT(varchar(100),a.KqDate, 23) date,
'5'+cast(CardId as varchar) carid,
right(CONVERT(varchar(16), DATEADD(ss,a.KqTime, cast('00:00:00' AS datetime)), 121),5) as checktime,
a.DevID as clockid,
b.employeeid
from [192.168.3.101

].[HsSmartHR170921].dbo.KQ_KqData a,employee b
where b.code=case when @[DepartmentId]=‘NB001000’then '50'+cast(CardId as varchar) else '5'+cast(CardId as varchar) end

and a.EmpSysID is not null ) as info
where not exists (
select top 1 * from
(select [CardCode],[MachineCode],[DateTime]=CONVERT(varchar(100), Date, 23)+' '+CONVERT(varchar(100), Time, 24),employeeid
from [AttendanceCollect])
as collect
where collect.employeeid=info.employeeid
and substring(CONVERT(varchar(100), collect.[DateTime], 20),1,16)=info.date+' '+info.time)
) as cardinfo
left join [Machine] on [Machine].Code = cardinfo.clockid
left join [Card] on [Card].employeeid = cardinfo.employeeid
and [Card].UseTypeId='UseType_001' and ([card].RevokeDate is null or [card].RevokeDate>=GETDATE()-2)
left join [Employee] on [Employee].employeeid= [Card].EmployeeId
left join [Department] on [Department].DepartmentId=[Employee].DepartmentId
where [Card].CardNo is not null and cardinfo.date >='2017-03-01'
...全文

相关推荐

评论 15
收藏 已收藏
分享
返回顶部
get_D
MS-SQL Server 34,876 成员 254,635 内容