-- SET DATEFIRST to U.S. English default value of 7.
SET DATEFIRST 7;
SELECT
@@DATEFIRST;
SELECT
GETDATE()
, DATEPART(dw , GETDATE()) AS DayOfWeek;
-- January 1, 1999 is a Friday. Because the U.S. English default
-- specifies Sunday as the first day of the week, DATEPART of 1999-1-1
-- (Friday) yields a value of 6, because Friday is the sixth day of the
-- week when you start with Sunday as day 1.
SET DATEFIRST 3;
SELECT
@@DATEFIRST;
-- Because Wednesday is now considered the first day of the week,
-- DATEPART now shows that 1999-1-1 (a Friday) is the third day of the
-- week. The following DATEPART function should return a value of 3.
SELECT
GETDATE()
, DATEPART(dw , GETDATE()) AS DayOfWeek;
SET DATEFIRST 7;
DATEFIRSTの設定に関係なく、DATEPART(1 =日曜日は常に)を取得するにはどうすれば処理できますか?DATEPIRSTを使用する場合のDATEFIRSTの処理方法
私は本当にケースを行い、減算したくない... 6日曜日
か、可能性を表し方法について
select datediff(day,0, getdate()) % 7
曜日の名前と希望する値の 'DayOfWeek'を持つテーブルを持ち、' DATEPART'の代わりに 'DATENAME'を使用してテーブルに参加させることができます。種類は煩雑ですが、うまくいくはずです – Lamak
モッドはどこにあるのですか? – SQLMason