SET DATEFIRST (Transact-SQL)

Imposta il primo giorno della settimana su un numero compreso tra 1 e 7.

Icona di collegamento a un argomentoConvenzioni della sintassi Transact-SQL

Sintassi

SET DATEFIRST { number | @number_var } 

Argomenti

number | **@**number_var

Valore integer che indica il primo giorno della settimana. Può essere uno dei valori seguenti.

Valore Primo giorno della settimana

1

Lunedì

2

Martedì

3

Mercoledì

4

Giovedì

5

Venerdì

6

Sabato

7 (default, U.S. English)

Domenica

Osservazioni

Per visualizzare l'impostazione corrente dell'opzione SET DATEFIRST utilizzare la funzione @@DATEFIRST.

L'opzione SET DATEFIRST viene impostata in fase di esecuzione, non in fase di analisi.

Autorizzazioni

È richiesta l'appartenenza al ruolo public.

Esempi

In questo esempio viene visualizzato il giorno della settimana in base a un valore di data e vengono illustrati gli effetti della modifica dell'opzione DATEFIRST.

-- 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

Vedere anche

Riferimento

Tipi di dati (Transact-SQL)
@@DATEFIRST (Transact-SQL)
Tipi di dati data/ora (Transact-SQL)
SET (Transact-SQL)

Guida in linea e informazioni

Assistenza su SQL Server 2005