title: How to add a constant column to a SQL query without parsing it?
body: <p>I have a complex query supplied by other part of the application and I need to add a constant column and pass the query for further processing (SSRS ServerReport). The query can consist of several queries connected with <code>UNION ALL</code> and can contain <code>ORDER BY</code>. </p>
  
  <p><strong>Edit:</strong> I forget to emphasize what is included in title <strong>without parsing.</strong> I don't know nothing about query (conditions, subqueries) so parsing and modified it is rather dangerous. </p>
  
  <p>Example:</p>
  
  <pre><code>declare @t table(id int)
  insert into @t values(1)
  insert into @t values(2) 
  </code></pre>
  
  <p>The query:</p>
  
  <pre><code>(select  id from @t where id=1
  union all
  select  id from @t where id=2) order by id desc
  </code></pre>
  
  <p>Required Output:</p>
  
  <pre><code>id | Par
  ----------
  2  | Hello   
  1  | Hello
  </code></pre>
  
  <p>Attempt (not working with ORDER BY):</p>
  
  <pre><code>SELECT *, 'Hello' Par from
  ((select  id from @t where id=1
      union all
      select  id from @t where id=2) order by id desc) tbl
  </code></pre>
  
  <p>Solution has to work on SQL Server 2008+.</p>