CREATE TABLE #DaysTable(tdays datetime)
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
WITH
CTE_Days AS
(
SELECT DATEADD(month, @month, DATEADD(month, -MONTH(@dataforDate), DATEADD(day, -DAY(@dataforDate) + 1, CAST(FLOOR(CAST(@dataforDate AS FLOAT)) AS DATETIME)))) Days
UNION ALL
SELECT DATEADD(day, 1, Days)
FROM CTE_Days
WHERE Days < DATEADD(day, -1, DATEADD(month, 1, DATEADD(month, @month, DATEADD(month, -MONTH(@dataforDate), DATEADD(day, -DAY(@dataforDate) + 1, CAST(FLOOR(CAST(@dataforDate AS FLOAT)) AS DATETIME))))))
)
insert into #dayatable
select * from
(
SELECT DATEADD(month, @month, DATEADD(month, -MONTH(@dataforDate), DATEADD(day, -DAY(@dataforDate) + 1, CAST(FLOOR(CAST(@dataforDate AS FLOAT)) AS DATETIME)))) Days
UNION ALL
SELECT DATEADD(day, 1, Days)
FROM CTE_Days
WHERE Days < DATEADD(day, -1, DATEADD(month, 1, DATEADD(month, @month, DATEADD(month, -MONTH(@dataforDate), DATEADD(day, -DAY(@dataforDate) + 1, CAST(FLOOR(CAST(@dataforDate AS FLOAT)) AS DATETIME))))))
)
しかし、これは私にエラーを与えます。