数据库中解析XML
简介:OPENXML方法使用一例实现导入功能
DECLARE @strProjGUID AS VARCHAR(50)
DECLARE @strProjCode AS
VARCHAR(50)
DECLARE @idocImpXml AS INT
DECLARE @xmlCount AS INT
DECLARE @i AS INT
DECLARE @m AS INT
DECLARE @strSql AS
NVARCHAR(4000)
EXEC sp_xml_preparedocument @idocImpXml OUTPUT,
@ImpXML ---获取文档句柄
--初始化项目
SELECT @strProjGUID =
ProjGUID,@strProjCode = ProjCode FROM OPENXML(@idocImpXml,'/ImpData')
WITH (ProjGUID
uniqueidentifier '@ProjGUID',
ProjCode CHAR(50) '@ProjCode')
SELECT
CostGUID, CostNameCode,CostCode,EstimateFoundation,Unit
,Qty,Price,HkqAmount,BqftRate,Amount,Remarks,GetMode
INTO #tbImpField
FROM
OPENXML(@idocImpXml,'/ImpData/row',2)
WITH
(
CostGUID UNIQUEIDENTIFIER ,
CostNameCode VARCHAR(40),
CostCode
VARCHAR(100),
EstimateFoundation VARCHAR(100),
Unit VARCHAR(50)
,
Qty MONEY ,
Price MONEY ,
HkqAmount MONEY ,
BqftRate MONEY ,
Amount MONEY ,
Remarks VARCHAR(4000),
GetMode VARCHAR(20)
)
---关闭句柄
EXEC sp_xml_removedocument @idocImpXml