SET DATEFIRST (Transact-SQL)

Legt den ersten Wochentag auf eine Zahl von 1 bis 7 fest.

Themenlink (Symbol)Transact-SQL-Syntaxkonventionen

Syntax

SET DATEFIRST { number | @number_var } 

Argumente

number | **@**number_var

Eine ganze Zahl, die den ersten Tag der Woche angibt. Dieses Argument einen der folgenden Werte annehmen.

Wert Erster Tag der Woche

1

Montag

2

Dienstag

3

Mittwoch

4

Donnerstag

5

Freitag

6

Samstag

7 (Standardwert, US-Englisch)

Sonntag

Hinweise

Verwenden Sie die @@DATEFIRST-Funktion, um die aktuelle Einstellung von SET DATEFIRST anzuzeigen.

Die Einstellung von SET DATEFIRST wird zur Ausführungszeit und nicht zur Analysezeit festgelegt.

Berechtigungen

Erfordert die Mitgliedschaft in der public-Rolle.

Beispiele

Im folgenden Beispiel wird der Wochentag für einen Datumswert angezeigt, und es wird gezeigt, wie sich Änderungen der DATEFIRST-Einstellung auswirken.

-- SET DATEFIRST to U.S. English default value of 7.
SET DATEFIRST 7;

SELECT CAST('1/1/1999' AS DATETIME) AS SelectDate, DATEPART(dw, '1/1/1999') 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 1/1/1999 
-- (Friday) yields a value of 6, because Friday is the sixth day of the 
-- week when starting with Sunday as day 1.

SET DATEFIRST 3;
-- Because Wednesday is now considered the first day of the week,
-- DATEPART should now show that 1/1/1999 (a Friday) is the third day of the 
-- week. The following DATEPART function should return a value of 3.
SELECT CAST('1/1/1999' AS DATETIME) AS SelectDate, DATEPART(dw, '1/1/1999') AS DayOfWeek;
GO

Siehe auch

Verweis

Datentypen (Transact-SQL)
@@DATEFIRST (Transact-SQL)
Datum und Uhrzeit (Transact-SQL)
SET (Transact-SQL)

Hilfe und Informationen

Informationsquellen für SQL Server 2005