Hi @Prusty, Parthasarathi (Cognizant)
As venkat answered, you could use ROW_NUMBER() function. However, there need some modification on the PARTITION BY clause.
Please check this query:
SELECT T1.ParentResourcecode,T1.Resourcecode,T1.Servicecode,T1.ChildService
,'CS'+CAST(ROW_NUMBER()OVER(PARTITION BY T1.ParentResourcecode,T1.Resourcecode,T1.Servicecode,T1.ChildService ORDER BY T1.Cell) AS VARCHAR(18)) AS ChildServiceGroup
FROM Table1 T1 LEFT JOIN Table2 T2 ON T1.ParentResourcecode = T2.ParentResourcecode
AND T1.Resourcecode = T2.Resourcecode
AND T1.Servicecode = T2.Servicecode
AND T1.Cell = T2.Cell
WHERE T1.Servicecode='PQR'
ORDER BY ChildServiceGroup,ChildService
Output:
Best regards,
LiHong
If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".
Note: Please follow the steps in our Documentation to enable e-mail notifications if you want to receive the related email notification for this thread.