1

我有这样的xml文件

<SamplingPlanProject>
   <CoordinateSystem>Lat/Long</CoordinateSystem>
   <InputUnits>M</InputUnits>
   <ProjectEngineerFirstName>Scott</ProjectEngineerFirstName>
   <ProjectEngineerLastName>Deaton</ProjectEngineerLastName>
   <ProjectName>1</ProjectName>
   <ProjectNumber>Test Project</ProjectNumber>
   <SamplingPlanProjectGUID>e91da635-0b5d-4e15-b71e-8e1986cf7a9d</SamplingPlanProjectGUID>
   <SamplingPlanProjectSite>
       <SiteID>Test Site</SiteID>
       <SamplingPlanProjectSiteGUID>42113b66-92b2-4387-b17b-3a346b980f3c</SamplingPlanProjectSiteGUID>
   </SamplingPlanProjectSite>
</SamplingPlanProject>

现在如何将这些元素值添加到 SQL Server 表中?我有单独samplingplanprojectsite的表,其中包含列siteidSamplingPlanProjectSiteGUID并且SamplingPlanProjectGUID

任何人都可以帮助形成这个吗?

如何为此编写代码以获取值rows

4

1 回答 1

0

试试这样: -

CREATE PROCEDURE AddEmp
    @empXml xml
AS

INSERT INTO Employee
(
    siteID,
    samplingPlanProjectSiteGUID,
    samplingPlanProjectGUID
)
VALUES
(
    @empXml.value('(/SamplingPlanProject/CoordinateSystem/InputUnits/SiteID)[1]', 'varchar(max)'),
   @empXml.value('(/SamplingPlanProject/CoordinateSystem/InputUnits/SamplingPlanProjectSiteGUID)[1]', 'varchar(max)'),
   @empXml.value('(/SamplingPlanProject/CoordinateSystem/InputUnits/SamplingPlanProjectGUID)[1]', 'varchar(max)'),
)

注意:- 我已将表的名称视为 EMP 和表列名称,如上所述。请根据您的要求更改值。

于 2013-09-10T18:25:41.927 回答