Join to the appropriate tables. E.g. to avoid calling
GetVesselPosition
SELECT ROW_NUMBER()OVER (ORDER BY M.EquipmentId) AS Row,
dbo.getEquipmentName(M.EquipmentId)EquipmentName,
MaintananceId,
ISNULL(VP.VesselPosition,'') AS PositionInVessal,
ClassCode,
MaintananceName,
dbo.getMaintananceType(MaintanaceType)MaintanaceType,
dbo.getFrequecyType(FrequencyType)FrequencyType,
Frequency,
CONVERT(VARCHAR(10), M.LastDoneDate, 105)LastDoneDate,
LastDoneRunningHours,CONVERT(VARCHAR(10), NextDueDate, 105) NextDueDate,
NextDueRunningHours, dbo.getResposibility(Responsibility)Responsibility,
C.Remarks,
C.JobCompletedAt,
C.NameOfPort,
C.JobCarriedOutBy,
C.NameOfWorkShop,
C.MaintanaceStatus
FROM dbo.PMS_TBL_MAINTANANCE_MASTER M
INNER JOIN PMS_TBL_MAINTANANCE_COMPLETION C ON C.MaintenanceId=M.MaintananceId
LEFT OUTER JOIN PMS_TBL_EQUIPMENT_MASTER E ON M.EquipmentId=convert(varchar(36),E.UniqueId)
LEFT OUTER JOIN PMS_TBL_SUB_EQUIPMENT_MASTER S ON M.EquipmentId=convert(varchar(36),S.UniqueId)
INNER JOIN PMS_TBL_EUIPMENT_VESSELPOSITION_MASTER VP where VP.VesselPositionId = E.PositionInVessal
Do the same for
- getMaintananceType
- getFrequecyType
- getEquipmentName
- getResponsibility
Potentially ne of the reasons you are having slow running queries with these joins is because you are converting Id's to varchar for each join - consider changing your schema so that ALL ids are int or bigint.
Are you actually retrieving data from PMS_TBL_SUB_EQUIPMENT_MASTER as you haven't use the S alias anywhere in your query.