Hi anonymous user
If there is an additional strictly increasing identity column in your source data table,then check this query:
;WITH CTE1 AS
(SELECT * FROM (SELECT Field,Value FROM Source_Table WHERE Field IN('Application Name','Application Form','Application Type','Application Version'))S
PIVOT(MAX(Value)FOR Field IN([Application Name],[Application Form],[Application Type],[Application Version]))P
),CTE2 AS
(SELECT * FROM (SELECT Field,Value,ROW_NUMBER()OVER(PARTITION BY Field ORDER BY identity_column)AS RNum FROM Source_Table WHERE Field IN('Finding Ref No','Port','Prepared','Project'))S
PIVOT(MAX(Value)FOR Field IN([Finding Ref No],[Port],[Prepared],[Project]))P
)
SELECT CTE1.*,[Finding Ref No],[Port],[Prepared],[Project]
FROM CTE1 CROSS JOIN CTE2
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.