MS SQL 2005:有什么方法可以临时将 T-SQL 脚本的系统日期设置为不同的日期吗?
我们有一堆依赖于今天的日期和运行时间的 T-SQL 脚本。如果某个星期没有运行,我们最终会在前一天临时设置系统时间,运行脚本,然后将其设置回来。
无论如何,是否可以在不更改原始脚本的情况下临时设置脚本的系统日期,例如执行脚本时或仅针对该会话?
We have a bunch of T-SQL scripts dependent on today's date and when they run. If one doesn't run on the week it should, we end up temporarily setting the system time a day before, run the script, then set it back.
Is there anyway to temporarily set the system date for a script without changing the original script, like when you execute it or only for that session?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将实际日期存储在表/临时表中。
然后检索或更新该日期,而不是调用
GetDate()
。You could store the actual date in a table / temp table.
THen retrieve or update that date rather then making a call to
GetDate()
.我找到了其他人的答案,在这里我分享它:“日期与操作系统日期和时间相关。请参见此处:http://msdn.microsoft.com/en-us/library/ms188383.aspx"。
您可以参考另一个问题模拟 SQL Server 实例上的当前日期?
I've found an answer by someone else, here I share it: "The date is tied to the OS date and time. See here: http://msdn.microsoft.com/en-us/library/ms188383.aspx".
You could refer to this other question Simulate current date on a SQL Server instance?