title: Dynamic table pivot on store procedure
body: <p>I'm doing a web interface to bind objects to users. I use SQL Server 2008 R2.</p>
  
  <p>It is object of a different kind. I have a desire to display a table dynamically in SQL to avoid doing it in PHP (which would be cumbersome and time to be displayed).</p>
  
  <p>I explain a bit of my data model.</p>
  
  <p>I have modules (Module Table) that have features (Feature Table). The features are so an inventory object that will bind them and a user. To make an inventory of an object functionality, I need a form and this form has fields (Table Field). These fields will have data that will be inserted in the " DataField " table. ID " id_group " allows grouping field values ​​from the same form.</p>
  
  <p>Until then, no worries. My problem comes when I want to show that I linked in my values ​​of my fields with a user.</p>
  
  <p>If I take the example of the "Mobile" module. It has three features "Number" which includes the mobile phone numbers , "Device" which includes the mobile phone models and "Link" that will allow me to bind a number ( "Number" ) with mobile ( "Devices" ) and users ( "User" ) .</p>
  
  <p>Functionality "Number" has the fields : "Short Number ", "Long Number" and "External Number"</p>
  
  <p>Functionality "Device" has the fields " Manufacturer " and " Model" .</p>
  
  <p>You can see data related to the "Number" feature :</p>
  
  <pre><code>ID |Short Number|Long Number|External Number|
  1  | 4545       | 3314545   | 0101014545    |
  2  | 1234       | 3311234   | 0101011234    |
  3  | 9876       | 3319876   | 0101019876    |
  </code></pre>
  
  <p>You can see data related to the "Device" feature:</p>
  
  <pre><code>ID |Manufacture|Device|
  4  | Alcatel   | 4018 | 
  5  | Alcatel   | 4028 | 
  6  | Cisco     | 7676 |
  </code></pre>
  
  <p>Tables I just see, I can get in with a SQL stored procedure that retrieves me the names of fields and added my column then shows me the data horizontally. </p>
  
  <p>Then I made ​​a connection to a number (Number) with a model (Devices) and a user (Users) in R_Data_Field_User table. It is here that I can not see my picture. Here's what I'd like to get dynamically depending on the module and functionality:</p>
  
  <pre><code>ID_LINK | User     | Number                    | Device         |
  1       | 1 Romain | 1 4545 3314545 0101014545 | 4 Alcatel 4018 |
  2       | 2 Jean   | 2 1234 3311234 0101011234 | 5 Alcatel 4028 |
  3       | 3 Pierre | 3 9876 3319876 0101019876 | 5 Alcatel 4028 |
  </code></pre>
  
  <p>I wish to make a stored procedure that spring me this table. I think we need only variable as the Feature ID </p>
  
  <p><a href="http://sqlfiddle.com/#!3/c2c47" rel="nofollow noreferrer">Here is my SQL Fiddle</a></p>
  
  <p>I hope I was clear ... </p>
  
  <p>I continued my research ... </p>