我只是將一些計算列添加到返回結果集的存儲過程中。我從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