我想要做什麼似乎是一個基本的int到小數,並且它不工作。我已經試過在插入之前執行演員,沒有更好的。我想使用十進制值來顯示百分比變化。代碼如下,以及輸出。任何幫助將是巨大的..SQL Server 2008 R2,麻煩鑄造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((@[email protected]) AS DECIMAL)/CAST(@priorCount AS DECIMAL),
CAST((@[email protected]) AS DECIMAL)/CAST(@avgAllCounts AS DECIMAL))
SELECT * FROM @tblVar
輸出:
19548
7107
8483
LatestCount PriorCount PctChgLatestVsPrior PctChgLatestVsAvg
7107 8483 0 -1
「它不工作」不是對實際問題的很好描述。 **什麼**不起作用?究竟? – Oded
評論的部分先於「它不工作」。演員。 – StatsViaCsh