SQLを使用してAccessで稼働日を取得する際の注意事項。これは、メモのために列に示されています。
SELECT t.Startdate,
DateDiff("d",t.Startdate,Date())-(DateDiff("ww",t.Startdate,Date())*2) AS InaccurateWorkDays,
DateDiff("ww",t.Startdate,Date()) AS WeekEndCount,
Weekday(Date()) AS EndDateWeekDay,
DateDiff("d",t.Startdate,Date()+1) Mod 7 AS Remainder,
IIf([Remainder]>0,
[WeekEndCount]+(([EndDateWeekDay]=7)*-0.5)
+(([EndDateWeekDay]=[Remainder])*-0.5)
+(([EndDateWeekDay]<[Remainder])*-1),
[WeekEndCount]) AS WeekEndCountAdjusted,
[WeekEndCountAdjusted]*2 AS WeekEndDays,
(Date()-t.Startdate)-[WeekEndDays] AS WorkDays
FROM table t
結果
Startdate 1 2 3 4 5 6 7
01/07/2012 15 2 6 6 2.5 5 14
02/07/2012 14 2 6 5 2 4 14
03/07/2012 13 2 6 4 2 4 13
04/07/2012 12 2 6 3 2 4 12
05/07/2012 11 2 6 2 2 4 11
06/07/2012 10 2 6 1 2 4 10
07/07/2012 9 2 6 0 2 4 9
08/07/2012 10 1 6 6 1.5 3 9
12/07/2012 6 1 6 2 1 2 6
18/07/2012 2 0 6 3 0 0 2
- InaccurateWorkDays
- WeekEndCount
- EndDateWeekDay
- 残り
- WeekEndCountAdjusted
- WeekEndDays
- WorkDays
ここにあるコードに基づく:http://forum.lessthandot.com/viewtopic.php?f = 102&t = 2510&p = 13924