I am looking for a way to concatenate the rows into a comma separated string.
I am looking for result as below where Result Seq column should concatenate the result column row by row values in order of Inspectiondate
within group of ProductNumber
, Purchaseordernumber
.
DECLARE @Table TABLE(PRODUCTNUMBER VARCHAR(10),PURCHASEORDERNUMBER
VARCHAR(11), INSPECTIONDATE date,BOOKINGTYPEDesc varchar(20),RESULT
VARCHAR(10));
INSERT INTO @table(PRODUCTNUMBER,PURCHASEORDERNUMBER,INSPECTIONDATE,BOOKINGTYPEDesc,RESULT)
VALUES
('117858-EUC', '400P0003270', '2023-04-27','FirstInspection','Pass'),
('117858-EUC', '400P0003270', '2023-04-29','FirstInspection', 'Fail'),
('117858-EUC', '400P0003270', '2023-05-02','SecondInspection', 'Reject'),
('117858-EUC', '400P0003270', '2023-05-15','FirstInspection', 'Abort'),
('117858-EUC', '400P0003270', '2023-05-20','FirstInspection', 'Pass'),
('117858-EUC', '400P0003270', '2023-05-21','SecondInspection', 'Fail'),
('117858-EUC', '400P0003327', '2023-04-27','FirstInspection', 'Pass'),
('117858-EUC', '400P0003327', '2023-04-28','FirstInspection', 'Pass'),
('117858-EUC', '400P0003327', '2023-04-29','FirstInspection', 'Pass'),
('117858-EUC', '400P0003327', '2023-05-01','FirstInspection', 'Fail'),
('117858-EUC', '400P0003327', '2023-05-03','Second', 'Fail'),
('117858-EUC', '400P0003327', '2023-05-09','FirstInspection', 'Reject'),
('117858-EUC', '400P0003327', '2023-05-12','Second', 'Pass'),
('117858-EUC', '400P0003327', '2023-05-15','FirstInspection', 'Pass')
Any help on the SQL query.