EOMONTH (Transact-SQL)EOMONTH (Transact-SQL)
適用対象:Applies to: SQL ServerSQL Server (サポートされているすべてのバージョン)
SQL ServerSQL Server (all supported versions)
Azure SQL データベースAzure SQL Database
Azure SQL データベースAzure SQL Database
Azure SQL Managed InstanceAzure SQL Managed Instance
Azure SQL Managed InstanceAzure SQL Managed Instance
Azure Synapse AnalyticsAzure Synapse Analytics
Azure Synapse AnalyticsAzure Synapse Analytics
Parallel Data WarehouseParallel Data Warehouse
Parallel Data WarehouseParallel Data Warehouse
SQL ServerSQL Server (サポートされているすべてのバージョン)
SQL ServerSQL Server (all supported versions)
Azure SQL データベースAzure SQL Database
Azure SQL データベースAzure SQL Database
Azure SQL Managed InstanceAzure SQL Managed Instance
Azure SQL Managed InstanceAzure SQL Managed Instance
Azure Synapse AnalyticsAzure Synapse Analytics
Azure Synapse AnalyticsAzure Synapse Analytics
Parallel Data WarehouseParallel Data Warehouse
Parallel Data WarehouseParallel Data Warehouse
この関数は、オプションのオフセットを使用して、指定された日付を含んでいる月の最後の日付を返します。This function returns the last day of the month containing a specified date, with an optional offset.
Transact-SQL 構文表記規則
Transact-SQL Syntax Conventions
構文Syntax
EOMONTH ( start_date [, month_to_add ] )
注意
SQL Server 2014 以前の Transact-SQL 構文を確認するには、以前のバージョンのドキュメントを参照してください。To view Transact-SQL syntax for SQL Server 2014 and earlier, see Previous versions documentation.
引数Arguments
start_datestart_date
月の最終日を返す日付を指定する日付の式。A date expression that specifies the date for which to return the last day of the month.
month_to_addmonth_to_add
start_date に追加する月数を指定する省略可能な整数式。An optional integer expression that specifies the number of months to add to start_date.
month_to_add 引数に値が指定されると、EOMONTH
は指定された月数を start_date に追加し、結果として生成された月の最終日を返します。If the month_to_add argument has a value, then EOMONTH
adds the specified number of months to start_date, and then returns the last day of the month for the resulting date. この整数式を追加したことによって有効な日付範囲をオーバーフローすると、EOMONTH
はエラーを生成します。If this addition overflows the valid range of dates, then EOMONTH
will raise an error.
戻り値の型Return Type
datedate
解説Remarks
EOMONTH
関数は、SQL Server 2012 (11.x)SQL Server 2012 (11.x) 以降のサーバーに対してリモート処理が可能です。The EOMONTH
function can remote to SQL Server 2012 (11.x)SQL Server 2012 (11.x) servers and higher. SQL Server 2012 (11.x)SQL Server 2012 (11.x) よりも前のバージョンのサーバーに対してリモート処理を実行することはできません。It cannot be remote to servers with a version lower than SQL Server 2012 (11.x)SQL Server 2012 (11.x).
例Examples
A.A. 明示的な datetime 型を使用する EOMONTHEOMONTH with explicit datetime type
DECLARE @date DATETIME = '12/1/2011';
SELECT EOMONTH ( @date ) AS Result;
GO
結果セットは次のようになります。Here is the result set.
Result
------------
2011-12-31
(1 row(s) affected)
B.B. 文字列パラメーターと暗黙的な変換を使用する EOMONTHEOMONTH with string parameter and implicit conversion
DECLARE @date VARCHAR(255) = '12/1/2011';
SELECT EOMONTH ( @date ) AS Result;
GO
結果セットは次のようになります。Here is the result set.
Result
------------
2011-12-31
(1 row(s) affected)
C.C. month_to_add パラメーターを使用する EOMONTH と使用しない EOMONTHEOMONTH with and without the month_to_add parameter
これらの結果セットに示されている値は、12/01/2011
から 12/31/2011
の実行日を含む期間を反映します。The values shown in these result sets reflect an execution date between and including 12/01/2011
and 12/31/2011
.
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
結果セットは次のようになります。Here is the result set.
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)