sql - 在 Access SQL 中查询 "workweek"

标签 sql ms-access-2007

我有一个来自 MS Excel 2007 的公式,它返回特定月份内特定日期的工作周。

B1 = IF(AND(WEEKDAY(A2,1)<>1,A2=DATE(YEAR(A2),MONTH(A2),1)),A2-WEEKDAY(A2,1)+7,IF(MONTH(A2)<>MONTH(A2-WEEKDAY(A2,1)+7),EOMONTH(A2,0),A2-WEEKDAY(A2,1)+7))

其中 A1 = 11/2012 且 B1 = 1/7/2012

我想在 MS Access 中使用此公式并将返回相同的值。我尝试编写一个查询,但行不通。

A1 列的字段名称为 [rdate],B1 列的字段名称为 [we_date]。

最佳答案

不要计算,要查询。请参阅:

Why should I consider using an auxiliary calendar table?

A calendar table can make it much easier to develop solutions around any business model which involves dates. Last I checked, this encompasses pretty much any business model you can think of, to some degree. Constant problems that end up requiring verbose, complicated and inefficient methods include the following questions:

  • How many business days between x and y?
  • What are all of the dates between the second Tuesday of March and the first Friday in April? 
  • On what date should I expect this shipment to arrive? 
  • What were the dates of all the Fridays in this quarter? 
  • ...  

关于sql - 在 Access SQL 中查询 "workweek",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9094847/

相关文章:

mysql - SQL数据库查询: Count(Distinct)

mysql - 使用更好的 MySQL 查询对最后消息进行分组

sql - 找出谁在从存储过程中执行该存储过程

ms-access - 微软 Access : how to add 1 row between 2 rows?

sql - 子查询返回 1 个结果,因此结果保持不同

database - 版本控制 Access 2007 数据库和应用程序

SQL 通配符包含该单词且不作为另一个单词的一部分

php - 金库每日余额登记册

java - 使用 SQL 在 Access 中选择特定值

ms-access - Access中的"join expression not supported"