title: MSSQL Stored Procedure - Return more than one column
body: <p><strong>(If you're here from Google, I <a href="https://stackoverflow.com/a/20940245/1478808">answered my own question</a> with a fix)</strong></p>
  
  <p>I have some trouble running a stored procedure from a WAMS (Windows Azure Mobile Service).</p>
  
  <p>It only returns the last row in the relevant table, when I would like to get all the relevant tables for the query.</p>
  
  <p>The stored procedure looks sort of like the following:</p>
  
  <pre><code>DECLARE @id bigint
  
  SET @id = 0
  
  IF @var IS NOT NULL AND @var!= 0
  BEGIN
      SELECT @id = id FROM intersection WHERE var = @var
      IF @id IS NOT NULL
      BEGIN
          SELECT row1, row2, row3 FROM relevant_table WHERE id = @id
      END
  END
  </code></pre>
  
  <p>As you can see, I'm trying to return some rows based on a variable I've defined using the WA SQL Manager Interface.</p>
  
  <p>The procedure executes as it is now, however it only returns the last row I've ever defined, and not all of the rows that's relevant to the ID I get from the 'intersection' table.</p>
  
  <p>My WAMS API script is pretty basic. Executes the Stored Procedure based on a query string value, saves it to a response variable, which it will return.</p>
  
  <p>My intersection table is structured like the following:</p>
  
  <pre><code>intesection_id(int)  var(int)   id(int)-foreign key = fkey_0
  
  1                    10009      1
  2                    10009      2
  </code></pre>
  
  <p>And my relevant_table is like this:</p>
  
  <pre><code>id(int)-foreign key = fkey_0   information    information2   created
  
  1                              "some info"    "other info"   default = getdate()
  2                              "other info"   "even more"    --||--             
  </code></pre>
  
  <p>The "var" column is yet another foreign key, but that's to a table which is irrelevant to my problem.</p>