記錄根據當前月生成生前月的天數

DECLARE @monthDay INT;
SET @monthDay = DAY(DATEADD(MONTH, 1, GETDATE()) - DAY(GETDATE())); 

DECLARE @n INT;
SET @n = 1;
DECLARE @montDayhstr NVARCHAR(200);
SET @montDayhstr =''

WHILE @n <= @monthDay
    BEGIN
        
        SET @montDayhstr = @montDayhstr +'"'+ CAST(CONVERT(NVARCHAR(7), DATEADD(MONTH, -0, GETDATE()), 20)AS NVARCHAR(30))
            + '-' + CAST(@n AS NVARCHAR(4))+'",' ;
        SET @n = @n + 1;
    END;
    

PRINT @montDayhstr

--SELECT  CAST(CONVERT(NVARCHAR(7), DATEADD(MONTH, -0, GETDATE()), 20)AS NVARCHAR(30))

相關文章
相關標籤/搜索