程序执行环境:
WIN XP SP3
SQL 2005
VB6
(在我自己电脑上)
这个存储过程用了2年了,一直很快
昨天开始有问题了。搞不懂。
在查询分析器里运行下面的存储过程
结果是1秒就获取了结果(设定时间为最近一个月的时间)
而放到VB6中就等几分钟都无响应,最后手动关掉软件
VB6中使用ADODC。
该ADODC的代码是:
With Adodc1
.ConnectionString = cnn.cnnStr
.CommandType = adCmdText
.CommandTimeout = 0
.RecordSource = clsReport1.SQL
.Refresh
End With
clsReport1.SQL=“exec dbo.S_GetYRReportVolumePeopleWage '2013-03-01','07:00:00','2013-03-31','07:00:00'”
网上查询说是存储过程的执行计划的问题,而使用了
exec sp_recompile @objname='[S_GetYRReportVolumePeopleWage]'
后没有效果。仍然是查询分析器中快,程序中调用慢。
拜求解决方案
set ANSI_NULLS ON
set QUOTED_IDENTIFIER ON
GO
ALTER Proc [dbo].[S_GetYRReportVolumePeopleWage]
(
@m_SDate varchar(100),
@m_STime varchar(100),
@m_EDate varchar(100),
@m_ETime varchar(100)
)
AS
BEGIN
set @m_SDate=@m_SDate + ' ' + @m_STime
set @m_EDate=@m_EDate + ' ' + @m_ETime
select ISNULL(G_YRPeople.B_Class,'') as B_Class,B_People,
sum(case B_Process when '染色' then B_FactSum else null end) as '染色',
sum(case B_Process when '拉色' then B_FactSum else null end) as '拉色',
sum(case B_Process when '堵布回染' then B_FactSum else null end) as '堵布回染',
sum(case B_Process when '断头回染' then B_FactSum else null end) as '断头回染',
sum(case B_Process when '加色' then B_FactSum else null end) as '加色',
sum(case B_Process when '加色回染' then B_FactSum else null end) as '加色回染',
sum(case B_Process when '前处理' then B_FactSum else null end) as '前处理',
sum(case B_Process when '后处理' then B_FactSum else null end) as '后处理',
sum(case B_Process when '洗缸' then B_FactSum else null end) as '洗缸',
sum(case B_Process when '冲缸' then B_FactSum else null end) as '冲缸',
sum(case B_Process when '剥色' then B_FactSum else null end) as '剥色',
sum(case B_Process when '落水' then B_FactSum else null end) as '落水',
sum(case B_Process when '染色' then B_FactSum else 0 end) +
sum(case B_Process when '拉色' then B_FactSum else 0 end) +
sum(case B_Process when '堵布回染' then B_FactSum else 0 end) +
sum(case B_Process when '断头回染' then B_FactSum else 0 end) +
sum(case B_Process when '加色' then B_FactSum else 0 end) +
sum(case B_Process when '加色回染' then B_FactSum else 0 end) +
sum(case B_Process when '前处理' then B_FactSum else 0 end) +