MS SQL 2005:有什么方法可以临时将 T-SQL 脚本的系统日期设置为不同的日期吗?

发布于 2024-09-19 16:51:47 字数 136 浏览 2 评论 0原文

我们有一堆依赖于今天的日期和运行时间的 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梦途 2024-09-26 16:51:47

您可以将实际日期存储在表/临时表中。
然后检索或更新该日期,而不是调用 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().

赠我空喜 2024-09-26 16:51:47

我找到了其他人的答案,在这里我分享它:“日期与操作系统日期和时间相关。请参见此处: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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文