【发布时间】:2010-07-30 07:18:38
【问题描述】:
我已经创建了一个存储过程
CREATE PROCEDURE GetCustomerWiseSales(@StartDate nvarchar(10), @EndDate nvarchar(10))
AS
SELECT C.cCode, min(C.cName) as Customer, sum(P.BeerValue) as BeerValue, sum(P.RestGroup)as RestGroup
from Customers C
Join
(
SELECT Sales.CustomerID, SUM(SalesLog.Quantity * SalesLog.Price) as BeerValue, 0 RestGroup
FROM Sales INNER JOIN
SalesLog ON Sales.MemoNo = SalesLog.MemoNo
WHERE (pGroup=8 and pSize>500) and Sales.Billdate>=@StartDate and Sales.Billdate<=@EndDate
group by Sales.CustomerID
union all
SELECT Sales.CustomerID, 0 BeerValue,SUM(SalesLog.Quantity * SalesLog.Price) AS RestGroup
FROM Sales INNER JOIN
SalesLog ON Sales.MemoNo = SalesLog.MemoNo
WHERE (pGroup!=8) and Sales.Billdate>=@StartDate and Sales.Billdate<=@EndDate
group by Sales.CustomerID
)P
on P.CustomerID=C.cCode
group by C.cCode
这个 SP 在 Management Studio 中运行良好,并在我眨眼之前输出结果。但是当我通过数据访问层在 C# 应用程序中添加这个 SP 并使用 TableAdapter 预览窗口预览数据时,在第一次运行时显示数据需要 8-10 秒,在第二次运行时预览窗口抛出超时异常.我还添加了一个带有常规 SQL 的新 TableAdapter 来确认这个问题,但常规 SQL GetData 函数运行良好。
我不明白如何在 Management Studio 中使用相同的用户名和密码很好地运行相同的程序,而不是在 DAL 中运行。
任何帮助将不胜感激。
【问题讨论】:
标签: sql-server-2005 stored-procedures