0

Please look at my query

select tms.TeamName,
(select loc.LocID from Locations loc, Users usr where loc.UserID = usr.UserID and usr.TeamID = tms.TeamID)
from Teams tms

In this case LocID returns multiple values. I want it to come in single column with comma separated values. How can i proceed?

Thanks in advance - Manoj

1

1 Answer 1

2
select
  tms.TeamName,
  stuff(
    (select ','+cast(loc.LocID as varchar(10))
     from Locations as loc
      inner join Users as usr
        on loc.UserID = usr.UserID
     where usr.TeamID = tms.TeamID
     for xml path('')), 1, 1, '')
from Teams as tms
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Mikael Eriksson, It really worked for me this is what i wanted to execute exactly. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.