次のテーブル値関数から結果として 24 か月を取得します。これらの月を別のテーブルに挿入する必要があり、結果は次のようになります。
Week Period
1 2010-02-01
2 2010-02-01
3 2010-02-01
4 2010-02-01
5 2010-03-01
6 2010-03-01
7 2010-03-01
8 2010-03-01
9 2010-03-01
10 2010-04-01
11 2010-04-01
12 2010-04-01
13 2010-04-01
14 2010-05-01
15 2010-05-01
16 2010-05-01
17 2010-05-01
18 2010-06-01
19 2010-06-01
20 2010-06-01
21 2010-06-01
22 2010-06-01
23 2010-07-01
24 2010-07-01
25 2010-07-01
26 2010-07-01
27 2010-08-01
28 2010-08-01
29 2010-08-01
30 2010-08-01
31 2010-09-01
32 2010-09-01
33 2010-09-01
34 2010-09-01
35 2010-09-01
36 2010-10-01
37 2010-10-01
38 2010-10-01
39 2010-10-01
40 2010-11-01
41 2010-11-01
42 2010-11-01
43 2010-11-01
44 2010-12-01
45 2010-12-01
46 2010-12-01
47 2010-12-01
48 2010-12-01
49 2011-01-01
50 2011-01-01
51 2011-01-01
52 2011-01-01
53 2011-02-01
54 2011-02-01
55 2011-02-01
56 2011-02-01
57 2011-03-01
58 2011-03-01
59 2011-03-01
60 2011-03-01
61 2011-03-01
62 2011-04-01
63 2011-04-01
64 2011-04-01
65 2011-04-01
66 2011-05-01
67 2011-05-01
68 2011-05-01
69 2011-05-01
70 2011-06-01
71 2011-06-01
72 2011-06-01
73 2011-06-01
74 2011-06-01
75 2011-07-01
76 2011-07-01
77 2011-07-01
78 2011-07-01
79 2011-08-01
80 2011-08-01
81 2011-08-01
82 2011-08-01
83 2011-09-01
84 2011-09-01
85 2011-09-01
86 2011-09-01
87 2011-09-01
88 2011-10-01
89 2011-10-01
90 2011-10-01
91 2011-10-01
92 2011-11-01
93 2011-11-01
94 2011-11-01
95 2011-11-01
96 2011-12-01
97 2011-12-01
98 2011-12-01
99 2011-12-01
100 2011-12-01
101 2012-01-01
102 2012-01-01
103 2012-01-01
104 2012-01-01
私の機能は次のとおりです。
ALTER FUNCTION [dbo].[sun_care1](@start_period date, @end_period date)
RETURNS @date TABLE (
Period date NOT NULL
)
AS
BEGIN
--& DATEADD (MONTH,1,@start_period)
WHILE (@end_period <= @start_period) BEGIN
SET @end_period= DATEADD(MONTH,1,@end_period)
--set @start_period =CAST(@start_period as varchar(max))
INSERT INTO @date VALUES (@end_period)
END;
RETURN;
END;