我有一个员工进出的时间。我想根据动态间隔条件进行分割
如果间隔为15:00
输入
EMP_ID SWIPE_IN SWIPE_OUT
4 2019-01-21 13:10:00.000 2019-01-21 15:45:00.000
所需的输出
EMP_ID SWIPE_IN SWIPE_OUT
4 2019-01-21 13:10:00.000 2019-01-21 15:00:00.000
4 2019-01-21 15:00:00.000 2019-01-21 15:45:00.000
答案 0 :(得分:0)
您可以使用类似的东西
Declare @Interval Varchar(30) = '15:00'
Insert Into [TableName]
Select EMP_ID, CAST(Convert(Varchar, SWIPE_OUT, 23)+ ' ' + @Interval As DateTime), SWIPE_OUT
From [TableName]
Where SWIPE_OUT > CAST(Convert(Varchar, SWIPE_OUT, 23)+ ' ' + @Interval As DateTime)
Update [TableName]
SET SWIPE_OUT = CAST(Convert(Varchar, SWIPE_OUT, 23)+ ' ' + @Interval As DateTime)
Where SWIPE_IN <> CAST(Convert(Varchar, SWIPE_OUT, 23)+ ' ' + @Interval As DateTime)
AND SWIPE_OUT > CAST(Convert(Varchar, SWIPE_OUT, 23)+ ' ' + @Interval As DateTime)