0
我有一個人力資源系統,我需要看看新的休假(休假)請求是否與現有請求衝突。我這樣做是基於整天,但我需要做半天的比較......我如何確定兩個請假(休假)衝突(重疊)
這是我的數據結構(和數據格式)這一切都在SQL Server 2008 R2中完成。
StartDate (datetime)
EndDate (datetime)
'The following 2 variables show if the user is taking a half or a full day off.
'The options for each are listed and explained.
StartDateAMPM (int) 0=All Day (StartDate may or may not be the same as the EndDate),
1=AM, (User is out of the office only in the morning)
2=PM (User is out of the office only in the afternoon)
EndDateAMPM (int) 0="All Day"/"half day"/"StartDate = EndDate",
1=AM (The user is off for the morning only)
**NOTE This cannot be PM (as you cannot end a leave
with a half day in the afternoon)
**IF this is a "0", there are 3 possibilities --
A) a full day leave where the StartDate <> EndDate
B) a full day where the StartDate = EndDate
C) a partial day where StartDate = EndDate and the user
is off in the morning or the afternoon
所以我通過這個信息到數據庫和我想看看是否與現有的休假新休假衝突...這裏是代碼做了一個單一的一天:
Legend: @Start DateTime -- StartDate from new leave
@end DateTime -- EndDate from new leave
@StartDateAMPM (int) 0,1,2 (see above for details)
EndDateAMPM (int) 0,1 (see above for details)
select count(ID) from v_VacReqWHalfDays
where
(@Start BETWEEN StartDate and EndDate
OR @End BETWEEN StartDate and EndDate
OR (@Start <= StartDate and @End >=EndDate))
and kUserID = @UserID
如果計數(ID)> 0,存在衝突 -
我的問題是如何納入1/2天假...(人們可以採取全天或半天休息(早上或下午)
我想用TSQL來確定當前的休假請求衝突(重疊)與現有的和無法弄清楚如何做到這一點?
重疊的一般檢查是:'Start1 <= End2和Start2 <= End1'。 – HABO
如果日期範圍相同,這不起作用!檢查出來......讓我知道如果我錯了......發生過一次;-) –
'declare @ Start1 as Date ='19960218',@ End1 as Date ='19960315'; declare @ Start2 as Date = @ Start1,@ End2 as Date = @ End1; select @ Start1作爲Start1,@ End1作爲End1,@ Start2作爲Start2,@ End2作爲End2,@ Start1 <= @ End2和@ Start2 <= @ End1時的情況,然後'重疊'else'無重疊'結束作爲狀態; '也許你遇到了沒有匹配時間的'DATETIME'值問題。 – HABO