So I have written on the joins and left joins etc.. for this xml project I am working on. However I am having some hell of a time with the XML portion. I can get all the data into a dataset. However I can't get the data to output the xml the way I would like to.
The TransactionTable left joins with the TimeEntry table on the transactionID . 1 to many the TransactionTable inner joins to the ClientTable 1 to 1
Data all comes out nicely with the left and inner join on my select statement. All data is there.
However I need it to output in the XML format I need. Can't figure out how to do it. Got close but everytime I get close I run into another roadblock.
see picture attached as well

<receivableInvoices>
<receivableInvoice refId="RECEIVABLEINVOICE-REFID-123">
<customerCompanyName>Acme Corp</customerCompanyName>
<customerEmailAddress>[email protected]</customerEmailAddress>
<invoiceNumber>123456</invoiceNumber>
<invoiceDate>2014-05-01</invoiceDate>
<billTo>
<address>
<line1>Acme Corp</line1>
<line2>123 Main Street</line2>
<line3>STE 100</line3>
<line4>Attn: Shipping</line4>
<city>Maitland</city>
<stateProvince>FL</stateProvince>
<postalCode>32751</postalCode>
<country>US</country>
</address>
<contact>
<name>Jane Doe</name>
<phoneNumber>555-555-5555</phoneNumber>
</contact>
</billTo>
<lineItems>
<lineItem>
<lineNumber>1</lineNumber>
<hours>75.00</hours>
<description>Description of the line item goes here.</description>
</lineItem>
</lineItems>
</receivableInvoice>
<receivableInvoices>
UPDATE: HERE is a sample query I am running
SELECT
tt.TransactionID as transactionID,
c.ClientID as customerRefID,
c.ClientCompany as customerCompanyName,
c.clientEmail as customerEmailAddress,
tt.TransactionInvNum as invoiceNumber,
tt.InvoiceDate as invoiceDate,
DATEADD(d,30,tt.InvoiceDate) as dueDate,
tt.TransactionInvBillAmt as totalAmount,
tt.TransactionInvBillAmt as balance,
'USD' as currencyCode,
'Invoice from Customer X' as description,
'30' as terms,
right(tt.PRojectID, (LEN(tt.projectid) - charindex(':',tt.projectid))) as purchaseOrderNumber,
right(tt.PRojectID, (LEN(tt.projectid) - charindex(':',tt.projectid))) as salesOrderNumber,
c.ClientCompany as "shipTo/address/line1",
c.ClientStreet as "shipTo/address/line2",
c.ClientStreet2 as "shipTo/address/line3",
c.ClientCity as "shipTo/address/city",
c.ClientState as "shipTo/address/stateProvince",
c.ClientZip as "shipTo/address/postalCode",
c.ClientFName + ' ' + c.ClientLName as "shipTo/contact/name",
c.ClientPhone as "shipTo/contact/phoneNumber",
c.ClientCompany as "billTo/address/line1",
c.ClientStreet as "billTo/address/line2",
c.ClientStreet2 as "billTo/address/line3",
c.ClientCity as "billTo/address/city",
c.ClientState as "billTo/address/stateProvince",
c.ClientZip as "billTo/address/postalCode"
FROM TransactionTable tt
INNER JOIN Client c
ON c.ClientID = tt.ClientID
LEFT JOIN timeentry te ON
te.TransactionID = tt.transactionID
WHERE tt.PayID is null
FOR XML PATH('receivableInvoice'), ROOT('receivableInvoices'), ELEMENTS
Output link Output of SQL