SQL Serverのクエリの日付

現在の月:

[DBNAME]を使用

行きます

変数を宣言し、データベースを使用します

@ReportGenerationDate DATEを宣言

@ReportMonth INTを宣言

@ReportMonthStartのDATEを宣言

@ReportMonthEndのDATEを宣言

SET @ReportGenerationDate = GETDATE()

SET @ReportMonth = MONTH(@ReportGenerationDate) - 1

SET @ReportMonthEnd = DATEADD(DAY、DATEPART(D、@ReportGenerationDate)* - 1、@ReportGenerationDate)

SET @ReportMonthStart = DATEADD(MONTH、-1、DATEADD(DAY、1、@ReportMonthEnd))

印刷@ReportMonthStart

印刷@ReportMonthEnd

- 4ヶ月前

 

ます。https://www.cnblogs.com/tutuyforever/p/6253107.htmlで再現

おすすめ

転載: blog.csdn.net/weixin_33814685/article/details/94682057