您好我正在尝试使用 XML 文件将数据插入到 SQL Server 数据库中,该文件具有如下一些数据。我能够在 OPENXML 中进行属性映射。如果我尝试将 XML 作为元素而不是属性传递,我会收到错误关于空插入。
以下是我的 XML 文件(包含属性)
<NewDataSet>
  <SampleDataTable id="20" Name="as" Address="aaa" Email="aa" Mobile="123" />
</NewDataSet>
我成功使用上述格式。如果我使用以下格式,我会遇到错误
<Customer>
  <Id>20</Id>
  <Name>Cn</Name>
  <Address>Pa</Address>
  <Email>bnso@gmail.com</Email>
  <Mobile>12345513213</Mobile>
</Customer>
这是我在 SQL 中的 openXML
 insert into @tempTable
    select * from openxml (@xmlHandle,'ROOT/Customer/',1)
    with (Cust_id int '@id',
          Customer_Name varchar(30) '@Name',
          Address varchar(30) '@Address',
          Email_id varchar(30) '@Email',
          Mobile_no bigint '@Mobile'
          )
    Insert into Test.dbo.tblCustomers (Cust_id,Customer_Name,Address,Email,Mobile_No) (select * from @tempTable)
请帮忙