我的要求是将@STARTDATE变量设置为01 [开始日] - 月[当前月] - 年[当年]并根据@ENDDATE月份变化28天,1月31日
DECLARE @STARTDATE DATETIME
DECLARE @ENDDATE DATETIME
根据月份我们将结束日期除以
DECLARE @MONTH int
SET @MONTH=(select MONTH(getdate()))
此处我无法在开始日期显示日期。
SET @STARTDATE = '01-+@MONTH+-+YEAR+'
IF (
@MONTH = 4
OR @MONTH = 6
)
SET @ENDDATE = '30-+@MONTH+-+YEAR+'
IF (@MONTH / 4 = 0)
SET @ENDDATE = '29-+@MONTH+-+YEAR+'
ELSE
SET @ENDDATE = '28-+@MONTH+-+YEAR+'
答案 0 :(得分:3)
select @STARTDATE = dateadd(m, datediff(m, 0, current_timestamp), 0) startdate,
@ENDDATE = dateadd(m, datediff(m, 0, current_timestamp) + 1, -1) enddate
答案 1 :(得分:1)