Sql Server 日期查询
当前月:
USE [DBName]
Go
Use Database, Declare Variables
DECLARE @ReportGenerationDate DATE
DECLARE @ReportMonth INT
DECLARE @ReportMonthStart DATE
DECLARE @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))
print @ReportMonthStart
print @ReportMonthEnd
--前四个月
生活不是用眼泪博得同情 而是用汗水赢得掌声