问题描述
如果那样的话,我使用的是 SS 2005
I'm using SS 2005 if that
我见过类似的示例代码
DECLARE @restore = SELECT @@DATEFIRST
SET DATEFIRST 1
SELECT datepart(dw,ADateTimeColumn) as MondayBasedDate,.... FROM famousShipwrecks --
SET DATEFIRST @restore
假设在查询运行时另一个查询设置了 DATEFIRST?
Suppose while the query is running another query sets DATEFIRST?
如果另一个查询依赖于 datefirst 是 7(例如)并且没有设置它,并且在我的查询运行时运行,那是他没有设置它的问题吗?或者有没有更好的方法来编写依赖于给定日期是第 1 天的查询.
If another query relies on datefirst being 7 (for example) and doesn't set it, and runs while my query is running, that's his problem for not setting it? or is there a better way to write queries that depend on a given day being day number 1.
推荐答案
@@DATEFIRST 对您的会话来说是本地的.您可以通过打开 Sql Server Management Studio (SSMS) 中的选项卡来验证它.在第一个选项卡中执行此代码:
@@DATEFIRST is local to your session. You can verify it by opening to tabs in Sql Server Management Studio (SSMS). Execute this code in the first tab:
SET DATEFIRST 5
并验证它不会影响另一个标签:
And verify that it doesn't affect the other tab with:
select @@datefirst
请参阅此 MSDN 文章.
这篇关于SQL Server SET DATEFIRST 范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!