title: How do I escape double quotes in attributes in an XML String in T-SQL?
body: <p>Pretty simple question - I have an attribute that I would like to have double quotes in.  How do I escape them?  I've tried</p>
  
  <ul>
  <li>\"</li>
  <li>""</li>
  <li>\\"</li>
  </ul>
  
  <p>And I've made the @xml variable both xml type and varchar(max) for all of them.</p>
  
  <pre><code> declare @xml xml --(or varchar(max) tried both)
  
   set @xml = '&lt;transaction&gt;&lt;item value="hi "mom" lol" 
      ItemId="106"  ItemType="2"  instanceId="215923801"  dataSetId="1" /&gt;&lt;/transaction&gt;'
  
   declare @xh int
   exec sp_xml_preparedocument @xh OUTPUT, @xml
  
   insert into @commits --I declare the table, just removed it for brevity
   select
      x.*
   from openxml(@xh,'/transaction/item')
    WITH (
      dataItemId int,
       dataItemType int,
      instanceId int,
      dataSetId int,
      value varchar(max)
    ) x
  </code></pre>