Итак, у меня есть следующий код - написанный сторонним поставщиком. Кто-нибудь может подсказать, какие индексы следует использовать для предотвращения поиска по закладкам? Вам также нужно содержимое UDF?
SELECT reportTbl.ReportDBID,
case when reportTbl.ResultStatus = 'P' then 'PRELIMINARY'
when reportTbl.ResultStatus = 'I' then 'INTERIM'
else reportTbl.ResultStatus end As Status, 1 as isAccessible,
dbo.repAb(reportTbl.ReportDBID) As Abnormality,
dbo.repAb(reportTbl.ReportDBID) As Importance,
reportTbl.UniversalServiceDescription as Title,
reportTbl.DiagnosticServSectID as ServiceDescription,
case when ResultStatus='X' then 'Cancelled' when ResultStatus='C' OR dbo.inferStatus(reportTbl.ReportDBID) = 'C' then 'Amended'
else reportTbl.DiagnosticServSectID end AS subCategory,
reportTbl.DiagnosticServSectID as subCategoryAlt,
case when cdrOth.FamilyName is not null then cdrOth.FamilyName else cdrOth.IDNumber end As Author,
reportTbl.ObservationDateTime
FROM reportTbl WITH (NOLOCK)
INNER JOIN patientTbl WITH (NOLOCK) ON reportTbl.patID = patientTbl.patID
LEFT OUTER JOIN cdrOth WITH (NOLOCK) ON reportTbl.ordID = cdrOth.SegCrossReferenceDBID
WHERE
patientTbl.recNumber ='111111111'
and reportTbl.ResultStatus IN ('G', 'H','I', 'J')
and reportTbl.DiagnosticServSectID IN ('E', 'F')
and reportTbl.UniversalServiceCode NOT IN ('A', 'B', 'C', 'D') -- there are roughly 750 options so using NOT IN is easier
ORDER BY ReportDBID