querying for “workweek” in Access SQL

六月ゝ 毕业季﹏ 提交于 2019-12-31 03:40:28

问题


I have a formula from MS Excel 2007 which returns the workweek of a certain date within a certain month.

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

where A1 = 11/2012 and B1 = 1/7/2012

I'd like to use this formula in MS Access and will return the same value. I'd tried to formulate a query but it won't work.

The field name of column A1 is [rdate] and column B1's field name is [we_date].


回答1:


Don't calculate, query. See:

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? 
  • ...  


来源:https://stackoverflow.com/questions/9094847/querying-for-workweek-in-access-sql

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!