我正在尝试做看似基本的 int 到小数的转换,但它不起作用。我已经尝试在插入之前执行演员表,没有更好的。我想使用十进制值来显示百分比变化。代码如下,连同输出。任何帮助都会很棒..
DECLARE @tblVar TABLE (LatestCount INT, PriorCount INT,
PctChgLatestVsPrior DECIMAL, PctChgLatestVsAvg DECIMAL)
DECLARE @tbl CHAR(30)
DECLARE @dte DATE
DECLARE @dte2 DATE
DECLARE @latestCount INT
DECLARE @priorCount INT
DECLARE @avgAllCounts INT
SET @tbl = 'tblDailyPricingAndVol'
SET @dte = '5/8/12'
SET @dte2 = '5/7/12'
EXEC spAvgOfCountByDateAddedByTable @tbl, @avg = @avgAllCounts OUTPUT
EXEC spCountOfDateAddedByTableAndDate @tbl, @dte, @count = @latestCount OUTPUT
EXEC spCountOfDateAddedByTableAndDate @tbl, @dte2, @count = @priorCount OUTPUT
INSERT INTO @tblVar
VALUES (@latestCount, @priorCount,
CAST((@latestCount-@priorCount) AS DECIMAL)/CAST(@priorCount AS DECIMAL),
CAST((@latestCount-@avgAllCounts) AS DECIMAL)/CAST(@avgAllCounts AS DECIMAL))
SELECT * FROM @tblVar
输出:
19548
7107
8483
LatestCount PriorCount PctChgLatestVsPrior PctChgLatestVsAvg
7107 8483 0 -1