0

我正在尝试运行一个访问 qry,它使用一个模块来执行一些计算。当我运行下面的代码时,我在表达式中得到未定义的函数。任何想法如何解决这一问题?

Dim conn As OleDbConnection = New OleDbConnection("Provider = Microsoft.ACE.OLEDB.12.0;Data Source = C:\Users\User\Database.accdb;")
Dim cmd As OleDbCommand = New OleDbCommand()
cmd.Connection = conn
cmd.CommandType = CommandType.StoredProcedure
cmd.CommandText = "qryTest"
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
4

1 回答 1

0

有关使用 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
  1. 不准确的工作日
  2. 周末计数
  3. 结束日期星期天
  4. WeekEndCountAdjusted
  5. 周末日
  6. 工作日

基于此处找到的代码:http: //forum.lessthandot.com/viewtopic.php?f=102 &t=2510&p=13924

于 2012-07-20T20:23:42.077 回答