SELECT DISTINCT SP.ProgramID AS [ProgramID],
FROM Tran_SpeakerProgram SP WITH(NOLOCK)
OUTER APPLY (SELECT DISTINCT TOP 1 FirstName AS SecondarySpeakerFirstName,
LastName AS SecondarySpeakerLastName,
TSC.SpeakerID AS SecondarySpeakerId
FROM Tran_ScheduleProgramSpeaker TSC WITH(NOLOCK)
INNER JOIN Tran_SpeakerProgram TSP ON TSC.ProgramID = TSP.ProgramID
INNER JOIN Mst_Speaker ms ON TSC.SpeakerID = ms.SpeakerID
WHERE TSC.ProgramID = TSP.ProgramID
AND TSC.SpeakerID != TSP.PrimarySpeakerID
AND TSC.ProgramID = SP.ProgramID
AND TSC.IsActive=1
AND TSC.IsDeleted=0 ) SECP
LEFT JOIN Tran_SpeakerExpenses TSE WITH (NOLOCK)
ON SECP.SecondarySpeakerId = TSE.SpeakerID
AND SP.ProgramID = TSE.ProgramID
AND TSE.TravelLogistic = 'Honoraria'
AND TSE.HonorariumType = 'A'
AND TSE.IsActive = 1
LEFT JOIN Tran_SpeakerExpenses TSEA WITH (NOLOCK)
ON SECP.SecondarySpeakerId = TSEA.SpeakerID
AND SP.ProgramID = TSEA.ProgramID
AND TSEA.TravelLogistic = 'Airfare'
AND TSEA.HonorariumType = 'A'
AND TSEA.IsActive = 1
LEFT JOIN Tran_SpeakerExpenses TSEL WITH (NOLOCK)
ON SECP.SecondarySpeakerId = TSEL.SpeakerID
AND SP.ProgramID = TSEL.ProgramID
AND TSEL.TravelLogistic = 'Lodging'
AND TSEL.HonorariumType = 'A'
AND TSEL.IsActive = 1
LEFT JOIN Tran_SpeakerExpenses TSEG WITH (NOLOCK)
ON SECP.SecondarySpeakerId = TSEG.SpeakerID
AND SP.ProgramID = TSEG.ProgramID
AND TSEG.TravelLogistic = 'Ground Transportation'
AND TSEG.HonorariumType = 'A'
AND TSEG.IsActive = 1
LEFT JOIN Tran_SpeakerExpenses TSEO WITH (NOLOCK)
ON SECP.SecondarySpeakerId = TSEO.SpeakerID
AND SP.ProgramID = TSEO.ProgramID
AND TSEO.TravelLogistic = 'Other'
AND TSEO.HonorariumType = 'A'
AND TSEO.IsActive = 1
LEFT JOIN Tran_ReconcileSpeakerExpenses TRS WITH (NOLOCK)
ON TSE.SpeakerExpensesID = TRS.SpeakerExpensesID
AND TRS.IsActive = 1
AND TRS.IsDeleted = 0
LEFT JOIN Tran_SpeakerProgramExpenses TSEV WITH (NOLOCK)
ON SP.ProgramID = TSEV.ProgramID
AND TSEV.ProgramExpenses = 'Audio/Visual'
AND TSEV.ProgramExpensesType = 'A'
AND TSEV.IsActive = 1
LEFT JOIN Tran_SpeakerProgramExpenses TSED WITH (NOLOCK)
ON SP.ProgramID = TSED.ProgramID
AND TSED.ProgramExpenses = 'Deposit'
AND TSED.ProgramExpensesType = 'A'
AND TSED.IsActive = 1
LEFT JOIN Tran_SpeakerProgramExpenses TSER WITH (NOLOCK)
ON SP.ProgramID = TSER.ProgramID
AND TSER.ProgramExpenses = 'Venue Rental'
AND TSER.ProgramExpensesType = 'A'
AND TSER.IsActive = 1
LEFT JOIN Tran_SpeakerProgramExpenses TSEWF WITH (NOLOCK)
ON SP.ProgramID = TSEWF.ProgramID
AND TSEWF.ProgramExpenses = 'Wi-Fi'
AND TSEWF.ProgramExpensesType = 'A'
AND TSEWF.IsActive = 1
LEFT JOIN Tran_SpeakerProgramExpenses TSEVP WITH (NOLOCK)
ON SP.ProgramID = TSEVP.ProgramID
AND TSEVP.ProgramExpenses = 'Valet Parking' -- This join does Time out
AND TSEVP.ProgramExpensesType = 'A'
AND TSEVP.IsActive = 1
*
ORDER BY SP.ProgramID;
外部应用需要优化,是否有任何联接替代方案或如何优化此查询。粗体问题导致问题需要3秒钟才能执行。 如果我评论外部申请,则需要11秒