Topic by Guy Law
I'm trying to get a query that will return primary email, office phone, and invoice count for a list of contacts. I have something like:
SELECT c.ID, c.Emails.EmailList.Address as Email,
c.Emails.EmailList.AddressType.Name,
c.Phones.PhoneList.Number as Phone,
c.Phones.PhoneList.PhoneType.ID PhoneType,
count(c.PrimaryContactIncidents.ReferenceNumber) as IncidentCount
FROM Contact c where c.ID in (44474867, 44474868)
Which returns something like:
<n0:CSVTable>
<n0:Name>Table0</n0:Name>
<n0:Columns>ID,Email,Name,Phone,PhoneType,IncidentCount</n0:Columns>
<n0:Rows>
<n0:Row>44474867,jdoe@usa.com,Email - Primary,8013629178,0,4</n0:Row>
<n0:Row>44474867,jdoe@usa.com,Email - Primary,8017506584,1,4</n0:Row>
<n0:Row>44474867,jdoe@usa.com,Email - Primary,,2,4</n0:Row>
<n0:Row>44474867,jdoe@usa.com,Email - Primary,,3,4</n0:Row>
<n0:Row>44474867,jdoe@usa.com,Email - Primary,8017506589,4,4</n0:Row>
<n0:Row>44474867,,Alternate Email 1,8013629178,0,4</n0:Row>
<n0:Row>44474867,,Alternate Email 1,8017506584,1,4</n0:Row>
<n0:Row>44474867,,Alternate Email 1,,2,4</n0:Row>
<n0:Row>44474867,,Alternate Email 1,,3,4</n0:Row>
<n0:Row>44474867,,Alternate Email 1,8017506589,4,4</n0:Row>
<n0:Row>44474867,,Alternate Email 2,8013629178,0,4</n0:Row>
<n0:Row>44474867,,Alternate Email 2,8017506584,1,4</n0:Row>
<n0:Row>44474867,,Alternate Email 2,,2,4</n0:Row>
<n0:Row>44474867,,Alternate Email 2,,3,4</n0:Row>
<n0:Row>44474867,,Alternate Email 2,8017506589,4,4</n0:Row>
</n0:Rows>
</n0:CSVTable>
I want it to return something like:
<n0:CSVTable>
<n0:Name>Table0</n0:Name>
<n0:Columns>ID,PrimaryEmail,OfficePhone,IncidentCount</n0:Columns>
<n0:Rows>
<n0:Row>44474867,jdoe@usa.com,8013629178,2</n0:Row>
<n0:Row>44474868,anotherdoe@usa.com,8017506584,2</n0:Row>
</n0:Rows>
</n0:CSVTable>
Thanks for any help.