0

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"
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

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
Rustbolts
  • 18
  • 4
  • Yes, but I want to show all record about same vup.UgovorId, because with this I got p.Naziv but I want all p.Naziv for one vup.UgovorId –  Feb 24 '18 at 18:23