SQL Server:显示超时过期的过程

时间:2014-11-07 14:27:09

标签: sql sql-server stored-procedures pivot

我有一个程序,我试图显示每个主题的每个人的出勤率。问题是我正在使用旋转来完成所需的工作。我面临的问题是本地主机上的程序在本地数据库上工作正常,但在服务器上我收到此错误:

  

超时已过期。操作完成之前经过的超时时间或服务器没有响应。

我的程序如下:

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

0 个答案:

没有答案
相关问题