2

我正在尝试使用 BizTalk 适配器(SQL 或 WCF-SQL)来创建多级分层架构。我的查询是这样的

SELECT
    CustomerQueueMessage.customer_queue_ID  AS CustomerQueueMsgID,
    CustomerMaster.customer_ID              AS [CustomerID],
    CustomerAddressType.address_type_ID     AS [AddressTypeID],         
    CustomerSalesRep.sales_rep_type_code    AS [SalesRepTypeCode]
 FROM CustomerQueue AS CustomerQueueMessage 
 INNER JOIN dbo.MDM_Customer                AS CustomerMaster       ON (CustomerQueueMessage.customer_queue_ID = CustomerMaster.customer_queue_ID)
 INNER JOIN dbo.MDM_CustomerAddressType     AS CustomerAddressType  ON (CustomerAddressType.customer_queue_ID  = CustomerMaster.customer_queue_ID)
 INNER JOIN dbo.MDM_CustomerSalesRep        AS CustomerSalesRep     ON (CustomerSalesRep.customer_queue_ID     = CustomerMaster.customer_queue_ID)
 FOR XML AUTO, TYPE, ELEMENTS, XMLDATA

当我使用 SQL 适配器生成架构时,我得到了这个结构

在此处输入图像描述

我想要的是

在此处输入图像描述

CustomerSalesRepCustomerAddressType下。我希望CustomerSalesRepCustomerAddressType处于同一级别,两者都在CustomerMaster下。

如果我删除 FOR XML 语句并使用 WCF-SQL 适配器生成架构,我没有层次结构,所有列都在同一级别。

有任何想法吗?最好我想使用 WCF-SQL 适配器来完成,但 SQL 也可以。

4

1 回答 1

1

你可以使用这个。

SELECT
    CustomerSalesRep.sales_rep_type_code    AS "CustomerQueueMessage/CustomerMaster/CustomerSalesRep/SalesRepTypeCode",
    CustomerAddressType.address_type_ID     AS "CustomerQueueMessage/CustomerMaster/CustomerAddressType/AddressTypeID",         
    CustomerMaster.customer_ID              AS "CustomerQueueMessage/CustomerMaster/CustomerID",
    CustomerQueueMessage.customer_queue_ID  AS "CustomerQueueMessage/CustomerQueueMsgID"
 FROM CustomerQueue AS CustomerQueueMessage 
 INNER JOIN dbo.MDM_Customer                AS CustomerMaster       ON (CustomerQueueMessage.customer_queue_ID = CustomerMaster.customer_queue_ID)
 INNER JOIN dbo.MDM_CustomerAddressType     AS CustomerAddressType  ON (CustomerAddressType.customer_queue_ID  = CustomerMaster.customer_queue_ID)
 INNER JOIN dbo.MDM_CustomerSalesRep        AS CustomerSalesRep     ON (CustomerSalesRep.customer_queue_ID     = CustomerMaster.customer_queue_ID)
 FOR XML PATH('SAPcustom'), TYPE, ELEMENTS

它会生成这样的 XML。

<SAPcustom>
  <CustomerQueueMessage>
    <CustomerMaster>
      <CustomerSalesRep>
        <SalesRepTypeCode>1</SalesRepTypeCode>
      </CustomerSalesRep>
      <CustomerAddressType>
        <AddressTypeID>1</AddressTypeID>
      </CustomerAddressType>
      <CustomerID>1</CustomerID>
    </CustomerMaster>
    <CustomerQueueMsgID>1</CustomerQueueMsgID>
  </CustomerQueueMessage>
</SAPcustom>
于 2017-12-29T08:44:07.023 回答