SQL Server XML中需要字符串文字

时间:2017-10-30 04:50:12

标签: sql-server xml

我想执行此代码,如您所见

UPDATE InquiryStatus
SET TotalCarburetorResult.modify(N'insert <item model=sql:variable("@Model") CarType=sql:variable("@CarType") SystemType=sql:variable("@SystemType")><count>1</count></item> into (/Result)[1]') where  UserId=@userid and SubmitDatetime=convert(date,@SubmitDatetime)

但是我收到了这个错误:

  

Msg 2225,Level 16,State 1,Line 78
  XQuery [InquiryStatus.TotalCarburetorResult.modify()]:预期字符串文字

作为注释,当我使用这种格式执行此查询时,它起作用:

UPDATE InquiryStatus
SET TotalCarburetorResult.modify(N'insert <item CarType="پراید" SystemType="2" model="1382"><count>100</count></item> into (/Result)[1]')

1 个答案:

答案 0 :(得分:0)

最终解决方案

    declare @myxml xml
    set @myxml='<item model="'+@Model+'" CarType="'+@CarType+'" SystemType="'+@SystemType+'"><count>1</count></item>'


UPDATE InquiryStatus
SET TotalCarburetorResult.modify(N'insert sql:variable("@myxml") into (/Result)[1]') where  UserId=@userid and SubmitDatetime=convert(date,@SubmitDatetime)