表达式中未定义的函数“Work_Days”

时间:2012-07-20 18:06:12

标签: vb.net ms-access

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

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()

1 个答案:

答案 0 :(得分: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. InaccurateWorkDays
  2. WeekEndCount
  3. EndDateWeekDay
  4. 剩余
  5. WeekEndCountAdjusted
  6. WeekEndDays
  7. 工作日
  8. 根据此处的代码:http://forum.lessthandot.com/viewtopic.php?f=102&t=2510&p=13924