0

我刚刚将几个计算列添加到返回结果集的存储过程中。我从 C#/.NET 调用它。新列(到最后)都返回值 0。这是我返回的第一行,以及它下面的存储过程:

Daily Pricing and Volume        5/4/2012    5229    5249    5256    0   0


ALTER PROCEDURE [dbo].[spProcedureStatsCollectionCountComparisons]

AS

DECLARE @MaxDataDownloadDate date

SET @MaxDataDownloadDate = dbo.MostRecentTradeDateForDataDownload()

SELECT ProcedureName, TradeDate, LatestCount, PriorCount, AvgAllCounts, 
    ((LatestCount-PriorCount)/PriorCount) AS PctChgLatestVsPrior, 
    ((LatestCount-AvgAllCounts)/AvgAllCounts) AS PctChgLatestVsAvg
FROM vwProcedureStatsCollectionCountComparisons
WHERE TradeDate = @MaxDataDownloadDate

我的问题是,我不能在存储过程的结果集中使用列别名',还是在工作中我遗漏了一些其他问题?提前致谢..

根据要求,相关的 C# 代码:

SqlDataReader collectionCounts = dal.ProcedureStatsCollectionCountComparisons();
int rowCounter = 4;
while (collectionCounts.Read())
{

    wkhst.Cells[rowCounter, 1] = collectionCounts["ProcedureName"];
    wkhst.Cells[rowCounter, 2] = collectionCounts["TradeDate"];
    wkhst.Cells[rowCounter, 3] = collectionCounts["LatestCount"];
    wkhst.Cells[rowCounter, 4] = collectionCounts["PriorCount"];
    wkhst.Cells[rowCounter, 5] = collectionCounts["AvgAllCounts"];
    wkhst.Cells[rowCounter, 6] = collectionCounts["PctChgLatestVsPrior"];
    wkhst.Cells[rowCounter, 7] = collectionCounts["PctChgLatestVsAvg"];

    rowCounter++;
}

excelApp.Visible = true;
4

1 回答 1

2

据我所知并根据提供的数据,它按预期工作。这是因为,您在执行以下操作。

SELECT ((5229 - 5249)/5249)

它总是返回“0”,因为第一个数字小于第二个。

编辑:

选择(CAST((5229 - 5249)作为浮动)/ CAST(5249作为浮动))

于 2012-05-07T19:40:17.690 回答