如何在 SQL Server 中将星期一设置为一周的第一天 [英] How to set monday as first day of week in SQL Server
问题描述
我正在一台机器上运行 SQL Server 2008,其区域设置将星期一作为一周的第一天.如果我在表中创建一个计算列来计算日期字段的星期几,那么星期一日期会得到 2 而不是 1.
I am running SQL Server 2008 on a machine with regional settings that have Monday as the first day of the week. If I create a computed column in a table to compute the day of week for a date field then I get 2 for a Monday date instead of 1.
是否需要为表、数据库或服务器设置某些属性?
Is there some property for the table or database or server that I need to set ?
推荐答案
一周的第一天取决于您的服务器语言设置.us_english 的默认设置是 7(星期日)
The first day of the week is based on your language settings of the server. The default setting for us_english is 7 (Sunday)
您可以使用 SELECT 查找当前的第一天@@DATEFIRST
但是,您可以为此使用 DATEFIRST
.只需将其放在查询的顶部
However, you can use DATEFIRST
for this. Just put it at the top of your query
SET DATEFIRST 1;
这会将星期一设置为当前连接的一周的第一天.
SET DATEFIRST 1;
this sets Monday to the first day of the week for the current connection.
http://technet.microsoft.com/en-us/library/ms181598.aspx
这篇关于如何在 SQL Server 中将星期一设置为一周的第一天的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!