0

Basically I want to take all the names (RequiredAccount, RequiredContact, RequiredOwner) for all the rows with a matching activityid and put them in there own column. So in short, I want to take multiple rows of data and put them in a Column. Basically I want to do what this person is doing (http://www.sqlprof.com/blogs/sqldev/archive/2008/03/31/how-to-list-multiple-rows-of-data-on-same-line.aspx) but I can't seem to get it to work.

SELECT DISTINCT 
    Appointment.ActivityId, Appointment.ScheduledStart, Appointment.OwnerIdName, Contact.AccountIdName, Appointment.new_ContactPersonName, 
        Appointment.Subject, Appointment.new_ColderNotes, Account.AccountId, Contact_1.ContactId, SystemUser.SystemUserId, SystemUser.FullName AS OptionalOwner, 
        Contact_1.FullName AS OptionalContact, Account.Name AS OptionalAccount, ActivityParty.PartyId, ActivityParty.ParticipationTypeMask, 
        Contact_1.FullName AS RequiredContact, Account.Name AS RequiredAccount, SystemUser.FullName AS RequiredOwner, Account.new_BusinessUnit
FROM
    Contact AS Contact_1 RIGHT OUTER JOIN
        Account RIGHT OUTER JOIN
        SystemUser RIGHT OUTER JOIN
        Appointment INNER JOIN
        ActivityParty ON Appointment.ActivityId = ActivityParty.ActivityId ON SystemUser.SystemUserId = ActivityParty.PartyId ON Account.AccountId = ActivityParty.PartyId ON
        Contact_1.ContactId = ActivityParty.PartyId LEFT OUTER JOIN
        Contact ON Appointment.new_ContactPerson = Contact.ContactId

And what I want if for the three Required columns to be in one column if there ActivityID Matches. So the first two rows would have two names in the new column.

Any ideas, help, etc.

Big Thanks!

1 Answers1

0

Simulating group_concat in sql server 2005

There are a couple of working examples in that thread, none of them are very pretty though :-/

Community
  • 1
  • 1
Ben English
  • 3,900
  • 2
  • 22
  • 32