you dont need any extra join. just tweak derived table as below and seeSelect dbo.[User].FirstName, dbo.[User].LastName, dbo.[User].Email, dbo.FormInstance.FormInstanceId, dbo.FormInstance.IsLocked, dbo.FormInstance.InsertedDate, dbo.FormInstance.UpdatedDate, dbo.Form.FormName, ts.SectionOrder, ts.Cnt AS TotalSectionsFrom dbo.[User]Inner Join dbo.FormInstanceOn dbo.[User].UserId = dbo.FormInstance.FkUserIdInner Join dbo.InstanceLastVistiedSectionInfoOn dbo.FormInstance.FormInstanceId = dbo.InstanceLastVistiedSectionInfo.FkFormInstanceIdInner Join dbo.FormOn dbo.FormInstance.FkFormId = dbo.Form.FormIdInner Join (SELECT *, COUNT(1) OVER (PARTITION BY FkFormId) AS Cnt FROM dbo.FormSection) tsOn dbo.InstanceLastVistiedSectionInfo.FkFormSectionId = ts.FormSectionIdAnd dbo.Form.FormId = ts.FkFormIdWhere dbo.FormInstance.FormInstanceId = @FormInstanceId
------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/https://www.facebook.com/VmBlogs