慕田峪9158850
该解决方案使用与Rodger基本相同的方法,除了生成矩阵的方法要复杂得多。注意:此解决方案的此输出与NETWORKDAYS不兼容。与Rodger的解决方案一样,这可以计算开始日期(@S)和结束日期(@E)之间的工作日数,而无需定义存储过程。它假定结束日期不在开始日期之前。使用相同的开始和结束日期将产生0.不考虑假期。这与Rodger的解决方案之间的主要区别在于矩阵和结果的数字串是由一个我没有包含的复杂算法构造的。该算法的输出由单元测试验证(参见下面的测试输入和输出)。在矩阵中,任何给定的x和y值对(WEEKDAY(@S)和WEEKDAY(@E)的交集产生两个值之间的工作日差异。分配顺序实际上并不重要,因为两者被加在一起绘制位置。营业日为周一至周五 | M T W T F S S-|--------------M| 0 1 2 3 4 5 5T| 5 0 1 2 3 4 4W| 4 5 0 1 2 3 3T| 3 4 5 0 1 2 2F| 2 3 4 5 0 1 1S| 0 1 2 3 4 0 0S| 0 1 2 3 4 5 0表中的49个值连接成以下字符串:0123455501234445012333450122234501101234000123450最后,正确的表达是:5 * (DATEDIFF(@E, @S) DIV 7) + MID('0123455501234445012333450122234501101234000123450', 7 * WEEKDAY(@S) + WEEKDAY(@E) + 1, 1)我已使用此解决方案验证了以下输入和输出:Sunday, 2012-08-26 -> Monday, 2012-08-27 = 0Sunday, 2012-08-26 -> Sunday, 2012-09-02 = 5Monday, 2012-08-27 -> Tuesday, 2012-08-28 = 1Monday, 2012-08-27 -> Monday, 2012-09-10 = 10Monday, 2012-08-27 -> Monday, 2012-09-17 = 15Monday, 2012-08-27 -> Tuesday, 2012-09-18 = 16Monday, 2012-08-27 -> Monday, 2012-09-24 = 20Monday, 2012-08-27 -> Monday, 2012-10-01 = 25Tuesday, 2012-08-28 -> Wednesday, 2012-08-29 = 1Wednesday, 2012-08-29 -> Thursday, 2012-08-30 = 1Thursday, 2012-08-30 -> Friday, 2012-08-31 = 1Friday, 2012-08-31 -> Saturday, 2012-09-01 = 1Saturday, 2012-09-01 -> Sunday, 2012-09-02 = 0Sunday, 2012-09-02 -> Monday, 2012-09-03 = 0Monday, 2012-09-03 -> Tuesday, 2012-09-04 = 1Tuesday, 2012-09-04 -> Wednesday, 2012-09-05 = 1Wednesday, 2012-09-05 -> Thursday, 2012-09-06 = 1Thursday, 2012-09-06 -> Friday, 2012-09-07 = 1Friday, 2012-09-07 -> Saturday, 2012-09-08 = 1Saturday, 2012-09-08 -> Sunday, 2012-09-09 = 0Monday, 2012-09-24 -> Sunday, 2012-10-07 = 10Saturday, 2012-08-25 -> Saturday, 2012-08-25 = 0Saturday, 2012-08-25 -> Sunday, 2012-08-26 = 0Saturday, 2012-08-25 -> Monday, 2012-08-27 = 0Saturday, 2012-08-25 -> Tuesday, 2012-08-28 = 1Saturday, 2012-08-25 -> Wednesday, 2012-08-29 = 2Saturday, 2012-08-25 -> Thursday, 2012-08-30 = 3Saturday, 2012-08-25 -> Friday, 2012-08-31 = 4Saturday, 2012-08-25 -> Sunday, 2012-09-02 = 0Monday, 2012-08-27 -> Monday, 2012-08-27 = 0Monday, 2012-08-27 -> Tuesday, 2012-08-28 = 1Monday, 2012-08-27 -> Wednesday, 2012-08-29 = 2Monday, 2012-08-27 -> Thursday, 2012-08-30 = 3Monday, 2012-08-27 -> Friday, 2012-08-31 = 4Monday, 2012-08-27 -> Saturday, 2012-09-01 = 5Monday, 2012-08-27 -> Sunday, 2012-09-02 = 5