尝试使用 while 循环将日期数据类型输入到表中。我的循环中断不起作用,输入值显示为 NULL。
帮助将不胜感激
DECLARE @StartDate DATE
DECLARE @countIndex INT
DECLARE @yearDate DATE
DECLARE @todaysDate DATE
SET @StartDate = GETDATE()
SET @yearDate = DATEADD(YEAR, 1,@StartDate)
CREATE TABLE DateLookup
(
DateID INT IDENTITY (1,1),
DateDescription Date
)
WHILE (DATEDIFF(DD,@StartDate, @yearDate)) <= 366
BEGIN
SET @countIndex = @countIndex +1
INSERT INTO DateLookup (DateDescription)
VALUES (DATEADD (DD,@countIndex,@todaysDate))--DAY(GETDATE()))
IF (@countIndex < 366)
Break
END