Here is the sql from the subreports. Do you think there should be some kind of indexes on views and/or tables? If so, what tables would that be, what columns should have indexes and what kind of indexes would you use?
What other changes do you think could be made here?
-
O_PA_AnnualComparisonRecords only key to table is never used in this table
SELECT
[endYear]
,[staffNumber]
,[PrincipalName]
,[cryrschoolID]
,[cryrschoolname]
,[pryrschoolID]
,[pryrschoolname]
,[sourceID]
,[source]
,[domainID]
,[domain]
,[itemID]
,[number]
,[item]
,[comparisonSchoolYear]
,[schoolYear]
,convert(decimal(5,2),[comparisonMean]) as comparisonMean
,convert(decimal(5,2),[principalMean]) as principalMean
,convert(decimal(5,2),[comparisonDifference]) as comparisonDifference
,convert(decimal(5,2),[districtcomparisonMean]) as districtcomparisonMean
,convert(decimal(5,2),[districtMean]) as districtMean
,convert(decimal(5,2),[districtComparisonDifference]) as districtComparisonDifference
,[ActiveYear]
FROM [dbo].[O_PA_AnnualComparisonRecords] WITH(NOLOCK)
where staffNumber = (@PstaffNumber) and
schoolYear = (@PschoolYear) and cryrschoolID = (@PschoolID)
order by sourceid, domainid, itemid
-
O_PA_PrincipalComments only key to table is never used in this table
SELECT distinct
c.[staffNumber]
,sy.label as schoolYear
,c.[schoolID]
,c.[comments]
,ua.lastName + ', ' + ua.firstName as PrincipalName
,sch.name
FROM [dbo].[O_PA_PrincipalComments] c WITH(NOLOCK) join
ODataStore.dbo.SchoolYear as sy WITH(NOLOCK) on c.endYear = sy.endyear join
O_APPS_DATA.dbo.vw_O_APPS_EmployeeList AS ua WITH(NOLOCK) on c.staffNumber = ua.staffNumber join
dbo.vw_O_IC_SCHOOL_LIST sch WITH(NOLOCK) on c.schoolID = sch.schoolID
where
c.staffNumber = (@PstaffNumber) and
sy.label = (@PschoolYear) and
sy.label <> '10-11' and
sch.schoolID = (@PschoolID)
-
O_PA_ResultCountTotals only key to table is never used in this table
SELECT
rsc.[endYear] as rsendYear
,syrs.label as rsschoolYear
,rssch.[schoolID] as rsschoolID
,rsc.[StudentCount]
,rsc.[ParentCount]
,rsc.[StaffCount]
,rsc.[TeacherCount]
FROM [dbo].[O_PA_ResultCountTotals] rsc WITH(NOLOCK) join
ODataStore.dbo.SchoolYear as syrs WITH(NOLOCK) on rsc.endYear = syrs.endyear join
dbo.vw_O_IC_SCHOOL_LIST rssch WITH(NOLOCK) on rsc.schoolID = rssch.schoolID
where
(syrs.label = (@PschoolYear)
or
syrs.label = convert(char(2),convert(int, substring(@PschoolYear, 0, charindex('-',@PschoolYear)) )-1)+'-'+substring(@PschoolYear, 0, charindex('-',@PschoolYear))
)
and
rssch.schoolID = (@PschoolID)
-
SELECT
[endYear]
,[staffNumber]
,[PrincipalName]
,[cryrschoolID]
,[cryrschoolname]
,[pryrschoolID]
,[pryrschoolname]
,[sourceID]
,[source]
,[domainID]
,[domain]
,[itemID]
,[number]
,[item]
,[comparisonSchoolYear]
,[schoolYear]
,convert(decimal(5,2),[comparisonMean]) as comparisonMean
,convert(decimal(5,2),[principalMean]) as principalMean
,convert(decimal(5,2),[comparisonDifference]) as comparisonDifference
,convert(decimal(5,2),[districtcomparisonMean]) as districtcomparisonMean
,convert(decimal(5,2),[districtMean]) as districtMean
,convert(decimal(5,2),[districtComparisonDifference]) as districtComparisonDifference
,[ActiveYear]
FROM [dbo].[O_PA_AnnualComparisonRecords] WITH(NOLOCK)
where schoolYear = (@PschoolYear) and staffNumber = (@PstaffNumber) and cryrschoolID = (@PschoolID)
order by sourceid, domainid, itemid
-
SELECT distinct
c.[staffNumber]
,sy.label as schoolYear
,c.[schoolID]
,c.[comments]
,ua.lastName + ', ' + ua.firstName as PrincipalName
,sch.name
FROM [dbo].[O_PA_PrincipalComments] c WITH(NOLOCK) join
ODataStore.dbo.SchoolYear as sy WITH(NOLOCK) on c.endYear = sy.endyear join
O_APPS_DATA.dbo.vw_O_APPS_EmployeeList AS ua WITH(NOLOCK) on c.staffNumber = ua.staffNumber join
dbo.vw_O_IC_SCHOOL_LIST sch WITH(NOLOCK) on c.schoolID = sch.schoolID
where sy.label = (@PschoolYear)
and sy.label <> '10-11'
and c.staffNumber = (@PstaffNumber) and sch.schoolID = (@PschoolID)
-
SELECT
rsc.[endYear] as rsendYear
,syrs.label as rsschoolYear
,rssch.[schoolID] as rsschoolID
,rsc.[StudentCount]
,rsc.[ParentCount]
,rsc.[StaffCount]
,rsc.[TeacherCount]
FROM [dbo].[O_PA_ResultCountTotals] rsc WITH(NOLOCK) join
ODataStore.dbo.SchoolYear as syrs WITH(NOLOCK) on rsc.endYear = syrs.endyear join
dbo.vw_O_IC_SCHOOL_LIST rssch WITH(NOLOCK) on rsc.schoolID = rssch.schoolID
where
(syrs.label = (@PschoolYear)
or
syrs.label = convert(char(2),convert(int, substring(@PschoolYear, 0, charindex('-',@PschoolYear)) )-1)+'-'+substring(@PschoolYear, 0, charindex('-',@PschoolYear))
)
and
rssch.schoolID = (@PschoolID)