EOMONTH (Transact-SQL)
Restituisce l'ultimo giorno del mese che contiene la data specificata, con un offset facoltativo.
Convenzioni della sintassi Transact-SQL
Si applica a: SQL Server (SQL Server 2012 tramite versione corrente), Database SQL di Windows Azure (versione iniziale tramite versione corrente). |
Sintassi
EOMONTH ( start_date [, month_to_add ] )
Argomenti
start_date
Espressione Date che specifica la data per cui restituire l'ultimo giorno del mese.month_to_add
Espressione intera facoltativa che specifica il numero di mesi da aggiungere a start_date.Se viene specificato questo argomento, EOMONTH aggiunge il numero di mesi specificato a start_date, quindi restituisce l'ultimo giorno del mese della data risultante. Se questa aggiunta supera l'intervallo valido di date, viene generato un errore.
Tipo restituito
date
Osservazioni
Questa funzione può essere eseguita in modalità remota in server SQL Server 2012 e versioni successive, ma non in server con versioni precedenti a SQL Server 2012.
Esempi
A.EOMONTH con tipo datetime esplicito
DECLARE @date DATETIME = '12/1/2011';
SELECT EOMONTH ( @date ) AS Result;
GO
Set di risultati:
Result
------------
2011-12-31
(1 row(s) affected)
B.EOMONTH con parametro di tipo stringa e conversione implicita
DECLARE @date VARCHAR(255) = '12/1/2011';
SELECT EOMONTH ( @date ) AS Result;
GO
Set di risultati:
Result
------------
2011-12-31
(1 row(s) affected)
C.EOMONTH con e senza il parametro month_to_add
DECLARE @date DATETIME = GETDATE();
SELECT EOMONTH ( @date ) AS 'This Month';
SELECT EOMONTH ( @date, 1 ) AS 'Next Month';
SELECT EOMONTH ( @date, -1 ) AS 'Last Month';
GO
Set di risultati:
This Month
-----------------------
2011-12-31
(1 row(s) affected)
Next Month
-----------------------
2012-01-31
(1 row(s) affected)
Last Month
-----------------------
2011-11-30
(1 row(s) affected)