SQL 中 sp_xml_preparedocument,openxml的使用

目的通过解析 XML 获取
QuestionID,QuestionTypeID,OptionText
SP:
create proc dbo.TestSaveSurvey
(
@XML ntext
)
as
begin
  
declare @doc int
  
declare @nError int
   
set @nError=50001
   
--sp_xml_preparedocument要读取的XML文档时@XML,
   exec sp_xml_preparedocument @doc output,@xml
  
--通过OpenXML获取行集视图,
   --/UIResponse/SurveyDetails/s/p/q/o 表示我要出来的节点
    select * into #NullOptionTemp from openxml(@doc,'/UIResponse/SurveyDetails/s/p/q/o',1)
             
/*
              QuestionID 列名称
              int 数据类型
              ../@QuestionId:Xpath,将那些节点映射到列
             
*/
             
with
              (
               QuestionId
int '../@QuestionId',
               QuestionTypeId
int '../@QuestionTypeId',
               OptionText
nvarchar(100) '@OptionText'
              ) 
             
where OptionText is null and QuestionTypeid in(2,3,4,5,6,10)
             
if exists(select * from #NullOptionTemp)
             
begin
                 
set @nError=50003
                 
goto error
             
end
             
delete from #NullOptionTemp
     error:
         
exec sp_xml_removedocument @doc
       
return @nError
end

Exec TestSaveSurvey '''text/xsl'' href=''styles/GenericPage.xslt''?>

''t like it!" NonSelect="0" OptionValue="1" VariableName="" PipingVariableName="" Fixed="0" Exclusive="0" />

'


你可能感兴趣的:(MSSQL)