2 回答
TA贡献1995条经验 获得超2个赞
你可以试试下面的脚本 -
DECLARE @StartDate AS DATETIME
DECLARE @EndDate AS DATETIME
DECLARE @CurrentDate AS DATETIME
SET @StartDate = '2019-11-01'
SET @EndDate = '2019-12-14'
SET @CurrentDate = @StartDate
WHILE (@CurrentDate < @EndDate)
BEGIN
IF datepart(DD,@CurrentDate) <=7
BEGIN
SET @CurrentDate = DATEADD(DD,-(DATEPART(DD,@CurrentDate)-1),@CurrentDate)
END
PRINT datepart(dd,@CurrentDate)/7 +1
SET @CurrentDate = DATEADD(DAY, 7, @CurrentDate);
END
TA贡献1773条经验 获得超3个赞
请将此用于具有周开始日期和结束日期的连击结果
DECLARE @StartDate datetime,
@EndDate datetime,
@CurrentDate datetime,
@IsTrue BIT=0
SET @StartDate = '2019-11-01'
SET @EndDate = '2019-12-14'
SET @CurrentDate=@StartDate
WHILE ( @CurrentDate <= @EndDate )
BEGIN
IF( Format(@CurrentDate, 'MM') != Format(@StartDate, 'MM')
AND @IsTrue = 0 )
BEGIN
SET @CurrentDate=Dateadd(month, Datediff(month, 0, @CurrentDate), 0)
PRINT @CurrentDate
SET @IsTrue=1
END
SELECT CONVERT(VARCHAR(20), ( Datepart(week, @CurrentDate) -
Datepart(week,
Dateadd(day, 1, Eomonth(
@CurrentDate, -1))) ) + 1),
@CurrentDate,
Dateadd(day, 6, @CurrentDate)
PRINT( CONVERT(VARCHAR(20), ( Datepart(week, @CurrentDate) -
Datepart(week,
Dateadd(day, 1, Eomonth(
@CurrentDate, -1))) ) + 1) )
SET @CurrentDate = Dateadd(day, 7, @CurrentDate);
END
添加回答
举报