SQL + Openxml +如何存储NVARCHAR数据

时间:2012-07-18 08:28:58

标签: sql openxml

您好我正在使用以下存储过程将xml数据插入表中。

PROCEDURE [dbo].[ExpertSystem_SET_QuestionData]
@XmlQue     NVARCHAR(MAX)
AS
set nocount on
 DECLARE @XmlHdl INT 

BEGIN


SET @XmlQue=N''+@XmlQue

EXEC sp_xml_preparedocument @XmlHdl OUTPUT,@XmlQue

    INSERT INTO ExpertSystem_Master 
    SELECT QIdx,@TemplateId,QDetailsx,IsYesx,IsNox,Eligibleyesx,Eligiblenox,0,0
    FROM 
    OPENXML(@XmlHdl,'/Template/QueInfo',1)
    WITH
    (    QIdx           INT '@QId',
         QDetailsx      Ntext '@QDetails',
         IsYesx         Ntext  '@IsYes', 
         IsNox          Ntext  '@IsNo', 
         Eligibleyesx   CHAR(1) '@Eligibleyes',
         Eligiblenox    CHAR(1) '@Eligibleno'
    )
   END

在这种情况下,我将值传递给参数

ExpertSystem_SET_QuestionData '<?xml version="1.0" encoding="UTF-16"?><Template TId="1"><QueInfo QId="1" QDetails="Are you " IsYes="Yes" IsNo="No" Eligibleyes="Y" Eligibleno="N"/><QueInfo QId="2" QDetails="  राज्य  " IsYes="Yes" IsNo="No" Eligibleyes="Y" Eligibleno="N"/><QueAns QId="1" isMsgFlag="N" Msg="you are not Eligible"/><QueAns QId="2" isMsgFlag="N" Msg="you are not eligible"/></Template>'

已插入数据,但会将其插入 ????? ,而不是**“राज्य”**。

当我将程序称为

ExpertSystem_SET_QuestionData 'N<?xml version="1.0" encoding="UTF-16"?><Template TId="1"><QueInfo QId="1" QDetails="Are you Domicile of maharashtra" IsYes="Yes" IsNo="No" Eligibleyes="Y" Eligibleno="N"/><QueInfo QId="2" QDetails="Have you passed Secondary  School 10th Examination?महाराष्ट्र राज्य मार्ग परिवहन महामंडळ " IsYes="Yes" IsNo="No" Eligibleyes="Y" Eligibleno="N"/><QueAns QId="1" isMsgFlag="N" Msg="you are not Eligible"/><QueAns QId="2" isMsgFlag="N" Msg="you are not eligible"/></Template>' 

我得到的错误是“XML解析错误0xc00ce556发生在第1行,靠近XML文本”N“

请你帮我解决这个问题,因为在运行时会调用该过程,因此任何数据都可以传递给@XmlQue变量。 那么我该如何用@XmlQue变量追加“N”???

提前致谢。

1 个答案:

答案 0 :(得分:0)

N应该在xml值之前。

ExpertSystem_SET_QuestionData N'<?xml version="1.0" ...