Hi @Santos, Luis ,
What is your version of SQL Server?
Please refer below and check whethe it is helpful to you.
DDL:
create table Request
(Request int)
insert into Request VALUES
(1),
(2),
(3)
create table Description
(Request int,
Line int,
description varchar(100))
insert into Description VALUES
(1,1,'this is a'),
(1,2,' request description'),
(2,1,'this is another'),
(2,2,' one'),
(3,1,'...and a third one')
SQL Server 2017 and later:
select a.Request,string_agg(b.description,'') within group (order by b.line) description
from Request a
inner join Description b
on a.Request=b.Request
group by a.Request
SQL Server 2016 and before:
SELECT a.Request, STUFF((
SELECT ' ' + b.description
from Description b
where b.Request=a.Request
order by b.Line
FOR XML PATH('')
), 1, 1, '') description
FROM Request a
Output:
Request description
1 this is a request description
2 this is another one
3 ...and a third one
Best regards
Melissa
If the answer is helpful, please click "Accept Answer" and upvote it.
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.
Hot issues November--What can I do if my transaction log is full?
Hot issues November--How to convert Profiler trace into a SQL Server table