title: Join two Tables with one have columns to rows
body: <p>I have a table with this structure:</p>
  
  <pre><code>Table 1: ID(PK) | &lt;other columns&gt;
                1 | otherdata
                2 | otherdata
  </code></pre>
  
  <p>the other table, It´s a list of documents (PDF,DOC,etc) with a URL to download. these documents is stored in my network.</p>
  
  <pre><code>Table 2: ID | IDDOC |    LINKDOC    | INFO
            1 |   1   | 'http://URL1' | 'Info1'
            1 |   2   | 'http://URL2' | 'Info2'
            2 |   1   | 'http://URL3' | 'Info3'
  </code></pre>
  
  <p>ID is the foreign key for Table 1,IDDOC is a foreign key to a 3rd table (below) that describe the document type:</p>
  
  <pre><code>Table 3: IDDOC | Name
              1  | 'Contract'
              2  | 'Notification'
  </code></pre>
  
  <p>I need to generate a query to join these tables and get a similar structure</p>
  
  <pre><code>ID | &lt;SomeCollumsTable1&gt; | NameDesc1 | NameURL1 | ... | NameDesc2 | NameURL2
  </code></pre>
  
  <p>Example output:</p>
  
  <pre><code>  ID | &lt;SomeCollumsTable1&gt; | ContractDesc | ContractURL   | NotificationDesc | NotificationURL
    1  | otherdata           | 'Info1'      | 'http://URL1' | 'Info2'          | 'http://URL2'
    2  | otherdata           | 'Info3'      | 'http://URL3' | ''               | ''
  </code></pre>
  
  <p>I.E. Generate many pairs Desc/URL as many records exits in "Table3". the sample data have 2 documents types and generate 4 columns.</p>
  
  <p>Currently i have subquerys to each desired document, but sounds very inefficient for me, the query is big and new documents i add in "Table3" need change in the whole query and need to just adjust the Where clause to indicate why IDDOC´s need. (using a IN clause)</p>
  
  <p>Or its better to manipulate this in my application (winforms/vb.net)?</p>
  
  <p>The App generate a report in EXCEL format.</p>