所以我寫了關於連接和左連接等。對於這個xml項目我正在努力。然而,我對XML部分有些茫然。我可以將所有數據導入數據集。但是我無法按照我想要的方式獲取數據來輸出xml。T-SQL和XML輸出
TransactionTable離開時與交易ID上的TimeEntry表連接。 1到很多 TransactionTable內部連接到ClientTable 1到1
數據都很好地出現在我的select語句的左連接和內連接上。所有數據都在那裏。
但是我需要它以我需要的XML格式輸出。無法弄清楚如何去做。接近了,但每次我接近我碰到另一個路障。
見圖附着以及
<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: 該處是我運行示例查詢
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 of SQL
那麼你想把你的查詢結果放入XML而不是行和列? – 2014-09-28 03:41:49
正確。我可以編寫所有的連接,並且已經閱讀了XML和T-SQL如何一起播放。但我不知道如何打破這個下降 – GrafixMastaMD 2014-09-28 03:46:38