如何使用此 sql squery 减少执行时间?执行和返回行需要一分钟多的时间。(在 Sql server management studio 2008 中执行)
if(@NotInvoiced =1)
BEGIN
Select @Command =
'select Distinct C.FileID, C.FileName, convert(nvarchar,C.DateReported,111) AS ''DateReported'',
C.FileDetailsPlainText, CFIT.Level3 as ''InvestigationType'', INV.FName + '' '' + INV.LName AS ''Name'',
convert(nvarchar,DD,111) AS ''DD'', i.FirstName + '' '' + i.LastName AS ''ReportedBy''
from CaseFiles C
join InvestigatorCaseFileAccess IA on C.FileID=IA.CaseFileID
LEFT OUTER JOIN CaseFileTimeBills tb on C.FileID=tb.FileID
LEFT OUTER JOIN CaseFileExpenses e on C.FileID=e.FileID
left join Element07a_Persons i on i.PersonID = c.PersonID
LEFT OUTER JOIN CaseFileInvestigationTypes CFIT ON C.InvestigationTypeID = CFIT.InvestigationTypeID
LEFT OUTER JOIN Investigators INV ON C.InvestigatorID = INV.InvestigatorID
where (tb.InvNumber IS null OR e.InvNumber IS null) and Deleted=0 and IA.InvestigatorID=' + CONVERT (nvarchar(max),@InvestigatorID) + ' and IA.AllowAccess = ''True''
and tb.FileID = C.FileID or e.FileID=C.FileID '
END