title: SQL Server query to generate custom report based on table data
body: <p>I am using SQL Server database which has tables <code>x</code>.</p>
  
  <p>Table: <code>x</code></p>
  
  <pre><code>x_id    Type        Text        ID
  -------------------------------------------
  | 1  |  Type1  |    txt1   |    id1
  | 2  |  Type2  |    txt2   |    id2
  | 3  |  Type3  |    txt3   |    id1
  | 4  |  Type3  |    txt4   |    id3
  </code></pre>
  
  <p>Here, Each ID can have different texts for Type1, Type2, Type 3 ... etc.</p>
  
  <p>I need to generate report which has fields ID, Type1_exists, Type2_exists, Type3_exists, Type1_Text, Type2_Text, Type3_Text where exists columns should say whether ID has that text or not (Y/N). If ID has record which has Type as "Type1" then Type1_exists value should be "Y" otherwise "N".</p>
  
  <p>So, Sample result that I am expecting is </p>
  
  <pre><code>ID    Type1_Exists  Type1_Text   Type2_Exists  Type2_Text  Type3_Exists Type3_Text
  ---------------------------------------------------------------------
  | id1  |      Y     | txt1   |        N        |      |     Y           |  txt3
  | id2  |      N     |        |        Y        | txt2 |     N           |  
  | id3  |      N     |        |        N        |      |     Y           |  txt4
  </code></pre>