我刚刚将几个计算列添加到返回结果集的存储过程中。我从 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;