SELECT S.[Id] as ServiceId ,S.[Code] as ServiceCode ,S.[IsArchive] as ServiceIsArchive ,S.[IsPublic] as ServiceIsPublic -- ,S.[NameXml] as ServiceNameXml ,S.[NameXml].value('(/Language/Ru)[1]','nvarchar(255)') as ServiceName -- ,TT.NameXml as TaskTypeNameXml ,TT.NameXml.value('(/Language/Ru)[1]','nvarchar(255)') as TaskTypeName ,TT.[IsArchive] as TaskTypeIsArchive ,TT.[NotDeleted] as TaskTypeNotDeleted -- ,R.[NameXml] as RoleNameXml ,R.[NameXml].value('(/Language/Ru)[1]','nvarchar(255)') as RoleName FROM [dbo].[Service] S left join [dbo].[ServiceTaskType] STT on STT.ServiceId = S.Id left join [dbo].[TaskType] TT on TT.Id = STT.TaskTypeId inner join [dbo].[ServiceTaskTypeWorkflowRole] STTWR on STTWR.ServiceTaskTypeId = STT.Id left join [dbo].[WorkflowRole] WR on WR.Id = STTWR.WorkflowRoleId left join [dbo].[Role] R on R.Id = WR.RoleId order by ServiceName,TaskTypeName,RoleName