为什么存储过程结果为零?
使用C#vs 2008.我在SQL Server 2005中有一个存储过程。使用Linq-to-SQL我执行存储过程,但结果为零。当我在Sql server中运行查询时,它工作正常
exec spGetInvoiceByDate '03/01/2011 00:00:00 AM','03/31/2011 11:59:59 PM'
上面的语法工作正常。
这是我的SQL Server存储过程
create procedure [spGetInvoiceByDate]
@Beginning_Date DateTime, @Ending_Date DateTime
as
begin
SELECT * INTO #temp1 FROM (
SELECT convert(varchar, ManifestPort.StartDate, 1)+'-'+CASE dbo.ManifestPort.EndDate WHEN '1800-01-01 00:00:00.000' THEN 'N/A' ELSE convert(varchar, ManifestPort.EndDate, 1) END AS [Date], Manifest.VesselName, Manifest.VoyageNo, DischargePort.PortName
, ManifestPort.Terminal, COUNT(Seal.ContainerNo) TotalContainers, 0 AS TotalHours, 0 AS TotalFee
FROM ManifestPort
INNER JOIN Manifest ON ManifestPort.ManifestNo = Manifest.ManifestNo
INNER JOIN DischargePort ON ManifestPort.PortCode = DischargePort.PortCode
INNER JOIN Seal ON ManifestPort.ManifestPortNo = Seal.ManifestPortNo
WHERE (StartDate BETWEEN @Beginning_Date AND @Ending_Date)
GROUP BY StartDate,EndDate, VesselName, VoyageNo, PortName, Terminal) AS a
SELECT * INTO #temp2 FROM (
SELECT convert(varchar, ManifestPort.StartDate, 1)+'-'+CASE dbo.ManifestPort.EndDate WHEN '1800-01-01 00:00:00.000' THEN 'N/A' ELSE convert(varchar, ManifestPort.EndDate, 1) END AS [Date], Manifest.VesselName, Manifest.VoyageNo, DischargePort.PortName,
ManifestPort.Terminal, COUNT(Seal.ContainerNo) STotalContainers, 0 AS STotalHours, 0 AS STotalFee
FROM ManifestPort
INNER JOIN Manifest ON ManifestPort.ManifestNo = Manifest.ManifestNo
INNER JOIN DischargePort ON ManifestPort.PortCode = DischargePort.PortCode
INNER JOIN Seal ON ManifestPort.ManifestPortNo = Seal.ManifestPortNo
WHERE (StartDate BETWEEN @Beginning_Date AND @Ending_Date ) AND Line = 'CSAV'
GROUP BY StartDate,EndDate, VesselName, VoyageNo, PortName, Terminal ) AS b
SELECT #temp1.Date,
#temp1.VesselName ,
#temp1.VoyageNo ,
#temp1.PortName ,
#temp1.Terminal ,
#temp1.TotalContainers ,
#temp1.TotalHours ,
#temp1.TotalFee, #temp2.STotalContainers, #temp2.STotalHours, #temp2.STotalFee FROM #temp1 INNER JOIN #temp2
ON #temp1.Date = #temp2.Date AND #temp1.PortName = #temp2.PortName AND #temp1.Terminal = #temp2.Terminal AND #temp1.VesselName = #temp2.VesselName
AND #temp1.VoyageNo = #temp2.VoyageNo
Order BY #temp1.VesselName, #temp1.VoyageNo
DROP TABLE #temp1
DROP TABLE #temp2
end
我使用这个C#Linq语法来执行存储过程:
DateTime firstDayOfMonth = Convert.ToDateTime("03/01/2011");
DateTime lastDayOfMonth = Convert.ToDateTime("03/31/2011");
var results = ProviderName.spGetInvoiceByDate(firstDayOfMonth,lastDayOfMonth);
为什么我总是得到结果为零?
有谁能告诉我如何减少这个问题?
在此先感谢,如果您有任何疑问,请询问。
没有找到相关结果
已邀请:
5 个回复
擅香
嗜蒂谷尘旱
将代码中的结束日期设置为2011年3月31日晚上11:59:59。
烫珊
柑恫祟
方法的代码(即使只是反映出来)吗?我愿意打赌它在内部做了我们不知道的事情。
朗排谎纷瘟
和ѭ7中相同。如果不匹配,您可以转换存储过程本身的格式。