*********************  导入 xml 文件DECLARE @idoc int
DECLARE @doc varchar(1000)
--sample XML document
SET @doc ='
<root>
  <Customer cid= "C1" name="Janine" city="Issaquah">
      <Order oid="O1" date="1/20/1996" amount="3.5" />
      <Order oid="O2" date="4/30/1997" amount="13.4">Customer was very satisfied
      </Order>
   </Customer>
   <Customer cid="C2" name="Ursula" city="Oelde" >
      <Order oid="O3" date="7/14/1999" amount="100" note="Wrap it blue 
             white red">
            <Urgency>Important</Urgency>
            Happy Customer.
      </Order>
      <Order oid="O4" date="1/20/1996" amount="10000"/>
   </Customer>
</root>
'
-- Create an internal representation of the XML document.
EXEC sp_xml_preparedocument @idoc OUTPUT, @doc-- Execute a SELECT statement using OPENXML rowset provider.
SELECT *
FROM OPENXML (@idoc, '/root/Customer/Order', 1)
      WITH (oid     char(5), 
            amount  float, 
            comment ntext 'text()')
EXEC sp_xml_removedocument @idoc

解决方案 »

  1.   

    *********************  导入 xml 文件DECLARE @idoc int
    DECLARE @doc varchar(1000)
    --sample XML document
    SET @doc ='
    <root>
      <Customer cid= "C1" name="Janine" city="Issaquah">
          <Order oid="O1" date="1/20/1996" amount="3.5" />
          <Order oid="O2" date="4/30/1997" amount="13.4">Customer was very satisfied
          </Order>
       </Customer>
       <Customer cid="C2" name="Ursula" city="Oelde" >
          <Order oid="O3" date="7/14/1999" amount="100" note="Wrap it blue 
                 white red">
                <Urgency>Important</Urgency>
                Happy Customer.
          </Order>
          <Order oid="O4" date="1/20/1996" amount="10000"/>
       </Customer>
    </root>
    '
    -- Create an internal representation of the XML document.
    EXEC sp_xml_preparedocument @idoc OUTPUT, @doc-- Execute a SELECT statement using OPENXML rowset provider.
    SELECT *
    FROM OPENXML (@idoc, '/root/Customer/Order', 1)
          WITH (oid     char(5), 
                amount  float, 
                comment ntext 'text()')
    EXEC sp_xml_removedocument @idoc
      

  2.   

    楼主说得是文件到数据库。
    在 txlicenhe(马可@李) 之前要把文件写道数据库中。
    这个过程可以采用各种方式
    1.xp_cmdshell ‘type filename.xml’ into mytable(一个表名称)
    然后..
    2.使用com组件,调用com组件
    3.使用xp_cmdshell textcopy ....到一个表中
    然后...