如何将XML数据转换为SQL Server表 哈吉·达姆拉特 13 454854 5532281 电话号码 0987262 532281 其他 配电盘 abc@gmail.com 电子邮件地址 01322 296 252 传真号码

如何将XML数据转换为SQL Server表 哈吉·达姆拉特 13 454854 5532281 电话号码 0987262 532281 其他 配电盘 abc@gmail.com 电子邮件地址 01322 296 252 传真号码,sql,sql-server,xml,Sql,Sql Server,Xml,我需要将其转换为SQL Server表: 电话号码 配电盘 电子邮件地址 传真号码 454854 5532281 0987262 532281 abc@gmail.com 01322 296 252 试试这个: <OrderContact> <Contact> <ContactName>Harj Dhamrait</ContactName> <ContactDescription>13</C

我需要将其转换为SQL Server表:

电话号码 配电盘 电子邮件地址 传真号码 454854 5532281 0987262 532281 abc@gmail.com 01322 296 252 试试这个:

<OrderContact>
    <Contact>
        <ContactName>Harj Dhamrait</ContactName>
        <ContactDescription>13</ContactDescription>
        <ListOfContactNumber>
            <ContactNumber>
                <ContactNumberValue />454854 5532281</ContactNumberValue>
                <ContactNumberTypeCoded>TelephoneNumber</ContactNumberTypeCoded>
            </ContactNumber>
            <ContactNumber>
                <ContactNumberValue>0987262 532281</ContactNumberValue>
                <ContactNumberTypeCoded>Other</ContactNumberTypeCoded>
                <ContactNumberTypeCodedOther>Switchboard</ContactNumberTypeCodedOther>
            </ContactNumber>
            <ContactNumber>
                <ContactNumberValue>abc@gmail.com</ContactNumberValue>
                <ContactNumberTypeCoded>EmailAddress</ContactNumberTypeCoded>
            </ContactNumber>
            <ContactNumber>
                <ContactNumberValue>01322 296 252</ContactNumberValue>
                <ContactNumberTypeCoded>FaxNumber</ContactNumberTypeCoded>
            </ContactNumber>
        </ListOfContactNumber>
    </Contact>
</OrderContact>
DECLARE@Data-XML=”
哈吉·达姆拉特
13
454854 5532281
电话号码
0987262 532281
其他
配电盘
abc@gmail.com
电子邮件地址
01322 296 252
传真号码
'
挑选
电话号码=xc.值('(ContactNumber[ContactNumberTypeCoded=“TelephoneNumber”]/ContactNumberValue/text())[1],'varchar(50)'),
交换机=xc.value('(ContactNumber[ContactNumberTypeCodedOther=“switcheard”]/ContactNumberValue/text())[1],'varchar(50)'),
EmailAddress=xc.value('(ContactNumber[ContactNumberTypeCoded=“EmailAddress”]/ContactNumberValue/text())[1],'varchar(50)'),
FaxNumber=xc.value('(ContactNumber[ContactNumberTypeCoded=“FaxNumber”]/ContactNumberValue/text())[1],'varchar(50)'
从…起
@Data.nodes('/OrderContact/Contact/ListOfContactNumber')作为XT(XC)
您应该获得所需的输出:

.nodes()
方法调用返回表示
节点的XML片段。您需要深入到该XML片段中,根据每个子节点在ContactNumberTypeCoded中的值提取每个子节点,然后将该值显示为所需的输出。

尝试以下操作:

<OrderContact>
    <Contact>
        <ContactName>Harj Dhamrait</ContactName>
        <ContactDescription>13</ContactDescription>
        <ListOfContactNumber>
            <ContactNumber>
                <ContactNumberValue />454854 5532281</ContactNumberValue>
                <ContactNumberTypeCoded>TelephoneNumber</ContactNumberTypeCoded>
            </ContactNumber>
            <ContactNumber>
                <ContactNumberValue>0987262 532281</ContactNumberValue>
                <ContactNumberTypeCoded>Other</ContactNumberTypeCoded>
                <ContactNumberTypeCodedOther>Switchboard</ContactNumberTypeCodedOther>
            </ContactNumber>
            <ContactNumber>
                <ContactNumberValue>abc@gmail.com</ContactNumberValue>
                <ContactNumberTypeCoded>EmailAddress</ContactNumberTypeCoded>
            </ContactNumber>
            <ContactNumber>
                <ContactNumberValue>01322 296 252</ContactNumberValue>
                <ContactNumberTypeCoded>FaxNumber</ContactNumberTypeCoded>
            </ContactNumber>
        </ListOfContactNumber>
    </Contact>
</OrderContact>
DECLARE@Data-XML=”
哈吉·达姆拉特
13
454854 5532281
电话号码
0987262 532281
其他
配电盘
abc@gmail.com
电子邮件地址
01322 296 252
传真号码
'
挑选
电话号码=xc.值('(ContactNumber[ContactNumberTypeCoded=“TelephoneNumber”]/ContactNumberValue/text())[1],'varchar(50)'),
交换机=xc.value('(ContactNumber[ContactNumberTypeCodedOther=“switcheard”]/ContactNumberValue/text())[1],'varchar(50)'),
EmailAddress=xc.value('(ContactNumber[ContactNumberTypeCoded=“EmailAddress”]/ContactNumberValue/text())[1],'varchar(50)'),
FaxNumber=xc.value('(ContactNumber[ContactNumberTypeCoded=“FaxNumber”]/ContactNumberValue/text())[1],'varchar(50)'
从…起
@Data.nodes('/OrderContact/Contact/ListOfContactNumber')作为XT(XC)
您应该获得所需的输出:


.nodes()
方法调用返回表示
节点的XML片段。您需要深入到XML片段中,根据每个子节点在ContactNumberTypeCoded中的值提取每个子节点,然后将该值显示为所需的输出。

您尝试了什么?你在哪里卡住了?让我们看看你的尝试?你尝试了什么?你在哪里卡住了?让我们看看你的尝试?