2016-08-09 3 views
-1

こんにちは、子ノードに属性を追加しようとすると文字列リテラルエラーが発生します。属性を正しく追加するためにコードを変更するにはどうすればよいですか。XMLデータ型のメソッド "modify"の引数1は、文字列リテラルでなければなりません

declare @count int=(select mxGraphXML.value('count(/mxGraphModel/root/Cell/@Value)','nvarchar') from TABLE_LIST 
         where Table_ListID=1234) 
         declare @index int=1; 
while @index<[email protected] 
begin 
declare @Value varchar(100)= @graphxml.value('(/mxGraphModel/root/Cell/@Value)[1]','nvarchar'); 

SET @graphxml.modify('insert attribute copyValueID {sql:variable("@Value ")} 
    as first into (/mxGraphModel/root/Cell)['+convert(varchar,@index)+']'); 
end 
    set @[email protected]+1; 
end 

答えて

0

あなたはCONCAT機能を使用する必要がありますaddition operatorを使用しています。したがって

'insert attribute copyValueID {sql:variable("@Value ")} 
as first into (/mxGraphModel/root/Cell)['+convert(varchar,@index)+']' 

は強制的に数値にされています。試してください:

CONCAT('insert attribute copyValueID {sql:variable("@Value ")} 
as first into (/mxGraphModel/root/Cell)[',convert(varchar,@index),']') 

+0

申し訳ありませんが、ここで私はgraphXMLの子ノードに新しい属性を挿入したいが、CONCATは単独では許可されていないか、graph.modify –

関連する問題