SQL Server:显示超时已过期的过程
我有一个程序,在这个程序中,我试图显示每一个科目的出勤率。问题是我正在使用旋转来完成所需的工作。我面临的问题是,在本地主机上,过程在本地数据库上运行正常,但在服务器上,我遇到以下错误: 超时已过期。操作完成前已过超时时间,或者服务器没有响应 我的程序如下所示:SQL Server:显示超时已过期的过程,sql,sql-server,stored-procedures,pivot,Sql,Sql Server,Stored Procedures,Pivot,我有一个程序,在这个程序中,我试图显示每一个科目的出勤率。问题是我正在使用旋转来完成所需的工作。我面临的问题是,在本地主机上,过程在本地数据库上运行正常,但在服务器上,我遇到以下错误: 超时已过期。操作完成前已过超时时间,或者服务器没有响应 我的程序如下所示: ALTER PROCEDURE [dbo].[prStudentLoadFullAttendance] @SemID int , @CourseID int AS BEGIN -- SET NOCOUNT ON
ALTER PROCEDURE [dbo].[prStudentLoadFullAttendance]
@SemID int ,
@CourseID int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;
-- Insert statements for procedure here
Declare @S nvarchar(1024)
Declare @Q nvarchar(Max)
set @S=''
---code for semester wise attendance
if(@SemID<>0)
begin
Select @S=@S+a.[Column] +',' from
(SELECT distinct ISNULL( dbo.tbSubjects.SubCode,'NoColumnName') as [Column] FROM dbo.tbAttendance INNER JOIN
dbo.tbAttendanceMaster ON dbo.tbAttendance.MasterAID = dbo.tbAttendanceMaster.AtdID INNER JOIN
dbo.tbStudent ON dbo.tbAttendance.StID = dbo.tbStudent.StudentID INNER JOIN
dbo.tbSubjects ON dbo.tbAttendanceMaster.SubID = dbo.tbSubjects.SubID LEFT OUTER JOIN
dbo.tbSemester ON dbo.tbSubjects.SemID = dbo.tbSemester.SemID
where tbSemester.SemID=@SemID ) as a
set @S=LEFT(@S,LEN(@S)-1)
print @S
set @Q='select Name,'+@S+',ODC'+',Percentage'+' from (SELECT distinct tbStudent.Name, dbo.tbSubjects.SubCode,
dbo.fnAttendanceView(dbo.tbAttendanceMaster.SubID,dbo.tbStudent.StudentID) AS Total ,dbo.fnodc(dbo.tbStudent.StudentID) as ODC,
left(dbo.fnCountTotalAttendance(dbo.tbStudent.StudentID),5) as Percentage
FROM dbo.tbAttendance INNER JOIN
dbo.tbAttendanceMaster ON dbo.tbAttendance.MasterAID = dbo.tbAttendanceMaster.AtdID INNER JOIN
dbo.tbStudent ON dbo.tbAttendance.StID = dbo.tbStudent.StudentID INNER JOIN
dbo.tbSubjects ON dbo.tbAttendanceMaster.SubID = dbo.tbSubjects.SubID LEFT OUTER JOIN
dbo.tbSemester ON dbo.tbSubjects.SemID = dbo.tbSemester.SemID
where tbSemester.SemID='+Cast(@SemID as nvarchar(10))+'
) sq
pivot(min(Total) for SubCode IN('+@S+') ) as pt
'
Execute sp_Executesql @Q
end
---code for course wise attendance
else
begin
Select @S=@S+a.[Column] +',' from
(SELECT DISTINCT ISNULL(dbo.tbSubjects.SubCode, 'NoColumnName') AS [Column]
FROM dbo.tbAttendance INNER JOIN
dbo.tbAttendanceMaster ON dbo.tbAttendance.MasterAID = dbo.tbAttendanceMaster.AtdID INNER JOIN
dbo.tbStudent ON dbo.tbAttendance.StID = dbo.tbStudent.StudentID INNER JOIN
dbo.tbSubjects ON dbo.tbAttendanceMaster.SubID = dbo.tbSubjects.SubID INNER JOIN
dbo.tbCourse ON dbo.tbSubjects.Course = dbo.tbCourse.CourseID
where tbCourse.CourseID=@CourseID ) as a
set @S=LEFT(@S,LEN(@S)-1)
print @S
set @Q='select Name,'+@S+',ODC'+',Percentage'+' from (SELECT DISTINCT
dbo.tbStudent.Name, dbo.tbSubjects.SubCode, dbo.fnAttendanceView(dbo.tbAttendanceMaster.SubID, dbo.tbStudent.StudentID) AS Total, dbo.fnOdc(dbo.tbStudent.StudentID) AS ODC,
LEFT(dbo.fnCountTotalAttendance(dbo.tbStudent.StudentID), 5) AS Percentage, dbo.tbSubjects.Course
FROM dbo.tbAttendance INNER JOIN
dbo.tbAttendanceMaster ON dbo.tbAttendance.MasterAID = dbo.tbAttendanceMaster.AtdID INNER JOIN
dbo.tbStudent ON dbo.tbAttendance.StID = dbo.tbStudent.StudentID INNER JOIN
dbo.tbSubjects ON dbo.tbAttendanceMaster.SubID = dbo.tbSubjects.SubID INNER JOIN
dbo.tbCourse ON dbo.tbSubjects.Course = dbo.tbCourse.CourseID
where dbo.tbCourse.CourseID='+Cast(@CourseID as nvarchar(10))+'
) sq
pivot(min(Total) for SubCode IN('+@S+') ) as pt
'
Execute sp_Executesql @Q
end
END
在不了解更多关于这些表的信息的情况下,它们的结构是什么?其中存储了多少行?这些表上有什么索引?在没有看到执行计划的情况下-这是不可能回答的…为什么不使用内置的PIVOT?请看这些表使用的是默认索引方案。执行计划也是默认的,这是一个超时的简单过程。查询超时多长时间后??SQL Server中没有默认索引。。。。。