Just In case you want to use CTE
DECLARE @tbl TABLE
(
RatingID INT,
Parameter_Order INT,
ProjectKey INT,
Comments NVARCHAR(MAX)
)
INSERT INTO @tbl
SELECT 792 , 0, 251,'A.quality has been improved of all deliverables, got appreciation from partner;B.all milestones on track;C.discussion in progress for salesforce team expansion team expansion plan for 2 .net resources;D.no infrastructure issue;E.team working on multiple business requirements and meeting all expectations of partner;F.dev and qa processes are being followed in aligned with partner'
UNION
SELECT 792 , 1, 251,'quality has been improved of all deliverables, got appreciation from partner'
UNION
SELECT 792 , 2, 251,'all milestones on track'
UNION
SELECT 792 , 3, 251,'discussion in progress for salesforce team expansion team expansion plan for 2 .net resources'
UNION
SELECT 792 , 4, 251,'no infrastructure issues'
UNION
SELECT 792 , 5, 251,'team working on multiple business requirements and meeting all expectations of partner'
UNION
SELECT 792 , 6, 251,'dev and qa processes are being followed in aligned with partner'
UNION
SELECT 827 , 0, 598,'A.quality has been consistent. no escalation from partner/stakeholders;B.working on release called crane;C.one attrition in teach support team;D.this has been consistent;E.we are all well connected with delivery stake holders.;F.this has been consistent;'
UNION
SELECT 827 , 1, 598,'quality has been consistent. no escalation from partner/stakeholders'
UNION
SELECT 827 , 2, 598,'working on release called crane'
UNION
SELECT 827 , 3, 598,'one attrition in teach support team'
UNION
SELECT 827 , 4, 598,'this has been consistent'
UNION
SELECT 827 , 5, 598,'we are all well connected with delivery stake holders.'
UNION
SELECT 827 , 6, 598,'this has been consistent'
;WITH CTE AS
(
SELECT RatingID ,MAX(Parameter_Order) Parameter_Order1
FROM @tbl
GROUP BY RatingID
)
, CTE2
as
(
SELECT t.RatingID ,Parameter_Order ,ProjectKey ,Comments,0 AS CurrentID ,
Parameter_Order1
FROM @tbl t
INNER JOIN CTE ON t.RatingID = cte.RatingID
WHERE Parameter_Order = 0
UNION ALL
SELECT CTE2.RatingID ,CTE2.Parameter_Order ,CTE2.ProjectKey ,CTE2.Comments+'||'+t.Comments,CTE2.CurrentID+1 AS CurrentID,
CTE2.Parameter_Order1
FROM CTE2
INNER JOIN @tbl t ON CTE2.RatingID = t.RatingID
WHERE t.Parameter_Order = CTE2.CurrentID+1
AND CTE2.CurrentID <=Parameter_Order1
)
SELECT * FROM CTE2 where currentid = Parameter_Order1
Regards,
Mitesh OSwal
+918698619998