As you can see I have 4 table to join below and I've search for the stuff function but it seems to support a single table only.
DECLARE @portal varchar(100) = 'A4E7890F-A188-4663-89EB-176D94DF6774'
select
list.[name] as [Company]
,list.[address] as [Address]
,b.[name] as [Business]
,comm.[value] as [Telephone Number]
,pp.title + ' ' + pp.first_name + ' ' + pp.last_name as [Contact Person]
from [panpages].[listings] as list
left join panpages.extra_communications as comm
on comm.listing_uuid = list.uuid and comm.type = 'Tel'
left join panpages.listing_people as lp
on lp.listing_uuid = list.uuid
left join panpages.people as pp
on pp.id = lp.person_id
left join panpages.listing_categories as r
on r.listing_uuid = list.uuid
left join panpages.categories as b
on b.uuid = r.category_uuid
where
list.[portal_uuid]=@portal and
list.[is_active]=1
This is my sql code and the data shown like below.
My current result appear like this :
Company | Address | Business | Telephone Number | Contact Person
A&B | Perak | Khmer Restaurants | 012541 | Mr. Yu Lee
A&B | Perak | F&B | 012541 | Mr. Yu Lee
King Co.| Ipoh | Paper Distributors | 021453 | Mrs. Cheng
King Co.| Ipoh | Paper Distributors | Null | Mrs. Cheng
DinoX | Sunway | Guesthouses | 0124587 | Mr. Hong
Dinox | Sunway | Guesthouses | 0124587 | Mr. Q
My expected result should be like this :
Company |Address| Business | Telephone Number | Contact Person
A&B | Perak | Khmer Restaurants, F&B| 012541 | Mr. Yu Lee
King Co.| Ipoh | Paper Distributors | 021453, Null | Mrs. Cheng
DinoX | Sunway| Guesthouses | 0124587 | Mr. Hong, Mr Q
Can somebody help me? I'm stuck around 4 hours because of this shit. Thanks in advance.