SSIS, How to calculate next wednesday based on any given date using ssis derived column expression

北城余情 提交于 2019-12-25 01:37:32

问题


I am creating a package which will store a report's generation date. on basis of that date need to derive the next wednesday date. Ex: report date is 11/11/2019 so wed date should be 13/11/2019. urgenty needed


回答1:


This Derived Column Expression should provide the next Wednesday's date.

DATEADD("DAY",((1 + DATEDIFF("DAY",(DT_DATE)"1/1/1970",GETDATE())) / 7) * 7 + 6,(DT_DATE)"1/1/1970")

Parts (inside out).

  • Days since 1/1/1970 + 1.
  • (Divide by 7) (Implicit Cast to Int) (Multiple by 7) will round it to last Thursday.
  • When added days back to 1/1/1970 (+6 days more) will move to next occurring Wednesday.

Notes

  • Without the initial 1 day offset, If GETDATE() is a Wednesday, the result will be GETDATE()'s date.
  • GETDATE() can be swapped out with GETUTCDATE() or a date Variable as needed.
  • The +6 can be moved back to +5 if a Tuesday is desired.


来源:https://stackoverflow.com/questions/58913536/ssis-how-to-calculate-next-wednesday-based-on-any-given-date-using-ssis-derived

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