Site icon Casino Novel

How to get data Horizontally from table Compliance Data Based on Part Id and Compliance Type Id?

I work on SQL Server 2014 I need to get data from compliance data table horizontally.

How to do that please?

Sample data as below

create table #ComplianceData 
(
    PartId int,
    ComplianceTypeID int,
    CompStatus nvarchar(30),
    VersionOrder int,
    ComplianceType nvarchar(30)
)

insert into # ComplianceData (PartId, ComplianceTypeID, CompStatus, VersionOrder, ComplianceType)
values (5090, 1, 'Compliant', 3, 'Rohs'),
       (5090, 1, 'NotCompliant', 40, 'Rohs'),
       (5090, 2, 'Compliant', 25, 'Reach'),
       (5090, 11, 'NotCompliant', 1, 'TSKA'),
       (2306, 1, 'Compliant', 3, 'Rohs'),
       (2306, 2, 'NotCompliant', 25, 'Reach'),
       (2306, 11, 'Compliant', 1, 'TSKA'),
       (4620, 1, 'NotCompliant', 3, 'Rohs'),
       (4620, 2, 'Compliant', 25, 'Reach'),
       (749120, 2, 'Compliant', 25, 'Reach')

Result required as

Exit mobile version