------------------------------------------------------------------------------------选出在最大年月和最小年月中的数据 begin----------------------------------------------------------------------------
SELECT DISTINCT CONVERT(NVARCHAR(4),ExecuteYear) + RIGHT('00' + CONVERT(NVARCHAR(2), ExecuteMonth), 2) ExecuteYM INTO #dataInput1 FROM #dataInput --拼接年月
DECLARE @maxYearMonth NVARCHAR(6);
DECLARE @minYearMonth NVARCHAR(6);
SELECT @maxYearMonth = MAX(ExecuteYM) ,@minYearMonth = MIN(ExecuteYM) FROM #dataInput1--获得最大年月和最小年月。
--3 删除操作
DELETE dbo.ReqCollectBack
WHERE CONVERT(NVARCHAR(4), ExecuteYear) + RIGHT('00'
+ CONVERT(NVARCHAR(2), ExecuteMonth),
2) <= @maxYearMonth
AND CONVERT(NVARCHAR(4), ExecuteYear) + RIGHT('00'
+ CONVERT(NVARCHAR(2), ExecuteMonth),
2) >= @minYearMonth
------------------------------------------------------------------------------------选出在最大年月和最小年月中的数据 end ----------------------------------------------------------------------------