I am using SQL SERVER 2016.
DECLARE @TESTTABLE TABLE
(
VenNumber INT,
VenName VARCHAR(60),
Ctypes varchar(50),
Purpose varchar(500),
Country varchar(20)
)
Insert @TESTTABLE
SELECT 23248,'Automoci','Organisation','Business','USA' UNION ALL
SELECT 23248,'Automoci','Organisation','Purchase order confirmation','USA' UNION ALL
SELECT 23248,'Automoci','Organisation','Supply Chain Contact','USA' UNION ALL
SELECT 23642,'Palau','Person','Business','ES' UNION ALL
SELECT 23642,'Palau','Person','Supply Chain Contact','ES' UNION ALL
SELECT 23642,'Palau','Person','Invoice','ES'
when values of VenNumber is same and ctypes = 'Organisation' then concatenate purpose value seperated by semicolon (;)
Output:
23248 Automoci Organisation Business;Purchase order confirmation;Supply Chain Contact USA
23642 Palau Person Business ES
23642 Palau Person Supply Chain Contact ES
23642 Palau Person Invoice ES
Kindly share suggestion