问题
I have query like this, and i shows me sort of good results
select
vup.UgovorId,
count(P.Naziv) as BROJNAZIVA
from
[TEST_Ugovori_Prod].dbo.VezaUgovorPartner as vup
inner join
[TEST_MaticniPodaci2].[dbo].[Partner] as p on vup.PartnerId = p.PartnerID
group by
vup.UgovorId
Results are like this (first row is vup.UgovorId, second is p.Naziv):
1264 1
1265 3
But I want to show all p.Naziv when that row has more then one for that vup.UgovorId like string so I would be like this:
1264 "Mark"
1265 "Jerry, Philip, Tom"
回答1:
I think this is the issue you are trying to solve?
I am not sure what technology you are using, but this may at least provide you some guidance.
So your code would look something like this:
select
vup.UgovorId,
substring(
(
Select ','+ P.Naziv AS [text()]
From [TEST_MaticniPodaci2].[dbo].[Partner] as p
Where vup.PartnerId = p.PartnerID
ORDER BY P.Naziv
For XML PATH ('')
), 2, 1000) [Names]
from
[TEST_Ugovori_Prod].dbo.VezaUgovorPartner as vup
group by vup.UgovorId
来源:https://stackoverflow.com/questions/48965582/how-to-show-all-names-for-identical-contract-in-t-sql