title: How to update an XML column with value from T-SQL built-in function?
body: <p>I have a MS SQL 2008 R2 Standard database. I have a column with <code>varchar(250)</code> data and a column with <code>xml</code>.</p>
  
  <pre><code>CREATE TABLE [dbo].[art](
  [id] [int] IDENTITY(1,1) NOT NULL,
  [idstr] [varchar](250) NULL,
  [rest] [xml] NOT NULL,
      CONSTRAINT [PK_art] PRIMARY KEY CLUSTERED ([id] ASC)
  )
  </code></pre>
  
  <p>The problem is I want to insert result of a string function into into xml, in about 140 records. I've tried to use <code>xml.modify</code> with dynamically generated text.</p>
  
  <pre><code>UPDATE [pwi_new].[dbo].[art]
  SET rest.modify('insert &lt;e&gt;&lt;k&gt;link&lt;/k&gt;&lt;v&gt;' 
        + my_string_function(idstr) + '&lt;/v&gt;&lt;/e&gt; into (/root)[1]')
    WHERE parent = 160
    AND idstr LIKE '%&amp;%'
  GO
  </code></pre>
  
  <p>However, I've got this error:</p>
  
  <pre><code>The argument 1 of the XML data type method "modify" must be a string literal.
  </code></pre>
  
  <p>Any ideas? I'd like to avoid using temporal fields, external languages and executing TSQL from generated string? (I've heard of <code>sql:variable</code> and <code>sql:column</code>, but this is a result of tsql function.)</p>