質問編集履歴
1
ソースを追加しました。何卒よろしくお願いいたします。
title
CHANGED
File without changes
|
body
CHANGED
@@ -7,4 +7,91 @@
|
|
7
7
|
基本的な質問にて恐縮ですが、本現象は仕様になりますでしょうか?
|
8
8
|
|
9
9
|
アドバイスなどいただけますと幸いです。
|
10
|
-
何卒よろしくお願いいたします。
|
10
|
+
何卒よろしくお願いいたします。
|
11
|
+
|
12
|
+
|
13
|
+
**どうにも先が見えない状況にてソースを掲載させていただきます。
|
14
|
+
問題点は@current_value_with_point_before_roundの小数点第一位が四捨五入されてしまうことでしたが、ISNULL(@current_point, 0)の@current_pointにNULLでない数値が代入された次の行からは、小数点以下が切り上げられず(0にならず)入力されることが分かりました。
|
15
|
+
説明不足かもしれませんが取り急ぎ。何卒よろしくお願いいたします。**
|
16
|
+
|
17
|
+
CREATE TABLE [dbo].[t_history]
|
18
|
+
([code] CHAR(6) NOT NULL
|
19
|
+
,[date] DATETIME NOT NULL
|
20
|
+
,[value] MONEY
|
21
|
+
,[compared_previous_day_yen] MONEY DEFAULT NULL
|
22
|
+
,[compared_previous_day_percent] DECIMAL(5,2) DEFAULT NULL
|
23
|
+
,[compared_previous_day_percent_before_round] DECIMAL(6,3) DEFAULT NULL
|
24
|
+
,[value_with_point] MONEY DEFAULT NULL
|
25
|
+
,[value_with_point_before_round] DECIMAL(19,9) DEFAULT NULL
|
26
|
+
,[initial_date] INT
|
27
|
+
,[point] MONEY
|
28
|
+
CONSTRAINT [pk_t_history] PRIMARY KEY([code], [date]))
|
29
|
+
|
30
|
+
DECLARE current_day CURSOR
|
31
|
+
FOR SELECT [date]
|
32
|
+
,[value]
|
33
|
+
,[initial_date]
|
34
|
+
,[point]
|
35
|
+
FROM [dbo].[t_history]
|
36
|
+
ORDER BY [code]
|
37
|
+
,[date]
|
38
|
+
|
39
|
+
DECLARE @current_date DATETIME
|
40
|
+
,@current_value MONEY
|
41
|
+
,@previous_value MONEY
|
42
|
+
,@current_initial_date INT
|
43
|
+
,@current_point MONEY
|
44
|
+
,@previous_point MONEY
|
45
|
+
,@current_value_with_point MONEY
|
46
|
+
,@current_value_with_point_before_round DECIMAL(19,9)
|
47
|
+
,@previous_value_with_point MONEY
|
48
|
+
,@previous_value_with_point_before_round DECIMAL(19,9)
|
49
|
+
|
50
|
+
OPEN current_day
|
51
|
+
|
52
|
+
FETCH NEXT FROM current_day
|
53
|
+
INTO @current_date
|
54
|
+
,@current_value
|
55
|
+
,@current_initial_date
|
56
|
+
,@current_point
|
57
|
+
|
58
|
+
WHILE @@FETCH_STATUS = 0
|
59
|
+
BEGIN
|
60
|
+
IF @current_initial_date = YEAR(@current_date) * 10000 + MONTH(@current_date) * 100 + DAY(@current_date)
|
61
|
+
BEGIN
|
62
|
+
SET @current_value_with_point_before_round = @current_value
|
63
|
+
SET @current_value_with_point = @current_value
|
64
|
+
UPDATE [dbo].[t_history]
|
65
|
+
SET [compared_previous_day_yen] = NULL
|
66
|
+
,[compared_previous_day_percent] = NULL
|
67
|
+
,[value_with_point] = @current_value_with_point
|
68
|
+
,[value_with_point_before_round] = @current_value_with_point_before_round
|
69
|
+
WHERE CURRENT OF current_day
|
70
|
+
END
|
71
|
+
ELSE
|
72
|
+
BEGIN
|
73
|
+
SET @current_value_with_point_before_round = @previous_value_with_point_before_round * ((1.000000000 * (@current_value + ISNULL(@current_point, 0))) / @previous_value)
|
74
|
+
SET @current_value_with_point = ROUND(@current_value_with_point_before_round, 0)
|
75
|
+
UPDATE [dbo].[t_history]
|
76
|
+
SET [compared_previous_day_yen] = @current_value - @previous_value
|
77
|
+
,[compared_previous_day_percent] = ROUND((1.000000000 * @current_value / @previous_value - 1) * 100, 2)
|
78
|
+
,[compared_previous_day_percent_before_round] = (1.000000000 * @current_value / @previous_value - 1) * 100
|
79
|
+
,[value_with_point] = @current_value_with_point
|
80
|
+
,[value_with_point_before_round] = @current_value_with_point_before_round
|
81
|
+
WHERE CURRENT OF current_day
|
82
|
+
END
|
83
|
+
|
84
|
+
SET @previous_value = @current_value
|
85
|
+
SET @previous_point = @current_point
|
86
|
+
SET @previous_value_with_point = @current_value_with_point
|
87
|
+
SET @previous_value_with_point_before_round = @current_value_with_point_before_round
|
88
|
+
|
89
|
+
FETCH NEXT FROM current_day
|
90
|
+
INTO @current_date
|
91
|
+
,@current_value
|
92
|
+
,@current_initial_date
|
93
|
+
,@current_point
|
94
|
+
END
|
95
|
+
|
96
|
+
CLOSE current_day
|
97
|
+
DEALLOCATE current_day
|