title: MSSQL print a message for XML
body: <p>I try to check my data bad if a table is existing and get the print output from my statement as XML</p>
  
  <p>For that I tried following code:</p>
  
  <pre><code>IF (
      EXISTS (
          SELECT *
          FROM INFORMATION_SCHEMA.TABLES
              WHERE TABLE_SCHEMA = 'dbo'
              AND TABLE_NAME = 'TABLE_NAME_I'
      )
  ) BEGIN
      PRINT 'Table allready exists in database'
      FOR XML AUTO
  END;
  </code></pre>
  
  <p>But the only thing I gat is:</p>
  
  <pre><code>Database operation failed: Incorrect syntax near the FOR keyword.
  </code></pre>
  
  <p>I also tried to set the <code>FOR XML AUTO</code> in front of <code>PRINT 'Table allready exists in database'</code> but the resault is the same.</p>
  
  <p>I'm using an JDBC Connector to realize the connection and the output.</p>
  
  <p>Is my project possible at all or do I have to combine it with something else to achieve this?</p>
  
  <p>Thanks in advance for the help.</p>
  
  <p>UPDATE
  <hr>
  I also tried now</p>
  
  <pre><code>SET @string = '&lt;MESSAGE&gt;Table allready exists in database&lt;/MESSAGE&gt;';
  SET @xml = CONVERT(XML, @string);
  SELECT @xml;
  </code></pre>
  
  <p>Here is my output which I get:</p>
  
  <pre><code>&lt;Data&gt;
     &lt;object_II&gt;
        &lt;_1/&gt;
     &lt;/object_II&gt;
  &lt;Data&gt;
  </code></pre>
  
  <p>Expected output:</p>
  
  <pre><code>&lt;Data&gt;
     &lt;object_II&gt;
        &lt;MESSAGE&gt;Table allready exists in database&lt;/MESSAGE&gt;
     &lt;/object_II&gt;
  &lt;Data&gt;
  </code></pre>