title: how create dynamic columns using tables data in sql server 2008?
body: <p>i have four tables like below in sql server 2008 :  </p>
  
  <p>TABLE 1 -> Users</p>
  
  <pre><code>                     UserID        UserName
                       -----------------------
                         1              Jhon
  </code></pre>
  
  <p>TABLE 2 -> PhoneBook</p>
  
  <pre><code>                     PhonebookID        UserID            Name             MobileNumber
                       -------------------------------------------------------------------
                         1                  1               MyBrother              252848
  </code></pre>
  
  <p>TABLE 3 -> PhonebookExtraField  </p>
  
  <pre><code>                     PhonebookExtraFieldID        UserID            ExtraFieldName    
                       -------------------------------------------------------------
                               1                      1               Age     
                               2                      1               Job
                               3                      1               Address    
  </code></pre>
  
  <p>TABLE 4 -> phoneBookExtraFieldData</p>
  
  <pre><code>phoneBookExtraFieldDataID    PhonebookExtraFieldID    PhonebookID    ExtraFieldValue    
  -----------------------------------------------------------------------------------------
           101                             1                  1               30
           102                             2                  1               Web Developer
           103                             3                  1               A.V. Rose
  </code></pre>
  
  <p>how can i write a query for output below :<br>
  mean i am looking for a way for creating dynamic columns using Tables data...</p>
  
  <pre><code>UserName  Phonebook(Name)  Phonebook(MobileNumber)  Age       Job           Address
  -------------------------------------------------------------------------------------
  Jhon          MyBrother            252848            30    Web Developer    A.V. Rose
  </code></pre>
  
  <p>what is the best way for doing this job?<br>
  how should i change my tables for this purpose?<br>
  thanks for attention and advance...</p>