You've been here long enough to know how to do this.
Here is a formatted version, for all those who struggle to optimise embedded SQL:DECLARE @PatientVisit_ID BIGINT = 379964759;
SELECT TherapyAdmin_ID,
RowVersionNumber,
Order_ID,
PatientVisit_ID = @PatientVisit_ID,
AdminNumber,
AdminComments,
AdminStartDateTime,
AdminEndDateTime,
ScheduledAdminNumber,
SchedAdminStartDateTime,
SchedAdminEndDateTime,
AdministeringStaff_ID,
CompletionStatus,
NotAdministeredCode,
OnHold,
AdminRouteCode,
AdminSiteCode,
AdminDeviceCode,
AdminMethodCode,
AdministeredAmount,
AdministeredUnits,
AdminRecordMethod,
Retrieved,
PrevAdminStartDateTime,
PrevAdminEndDateTime,
PreparationTime,
FollowUpTime,
LastPatientScanSeconds,
RetrieveTime,
AdminReportingSource,
AdministeredLocation_id,
UserDefinedFields,
ConsentGiver,
ConsentGivenDateTime,
WitnessStaff_ID,
WitnessTime
FROM TherapyAdmin WITH (INDEX(PatientOrder_TherapyAdmin_FK1_idx))
WHERE Order_ID IN
(
SELECT Order_ID
FROM PatientOrder
WHERE PatientOrder.PatientVisit_ID = @PatientVisit_ID
)
ORDER BY Order_ID,
ScheduledAdminNumber;
If you haven't even tried to resolve your issue, please don't expect the hard-working volunteers here to waste their time providing links to answers which you could easily have found yourself.