我只是将一些计算列添加到返回结果集的存储过程中。我从C#/ .NET调用它。新列(对端)都返回值0。这里是什么,我回来的第一行,并在它下面的存储过程:在SQL Server 2008 sprocs中不返回列别名'/计算列吗?
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;
向我们展示你的C#代码。应该没有问题,使用别名列 –
谢谢,刚刚添加它。 – StatsViaCsh
它必须是其他问题,我有SPs谁使用列别名在你的例子在2008年服务器,并且他们工作正常。你的*计数变量是什么数据类型?他们可以是无符号类型,并且由于(LatestCount-PriorCount)的结果<0,它的计算结果为0? – Treb