title: Stored procedure with parameters to return specific multiple columns, not all (*)
body: <p>Currently, I have a stored procedure that returns all the columns <code>(Select *)</code>. I am using this stored procedure to retrieve data from multiple tables, each table with different number of columns and obviously different column names, so <code>Select *</code> is convenient. However, now I need to retrieve only specific columns from each table so I want to pass the parameters something like this:</p>
  
  <pre><code>SELECT @param1, @param2, @param3, etc. 
  FROM @tableName 
  WHERE columnName = @tableId
  </code></pre>
  
  <p>The problem here is the number of parameters to be passed for the columns isn't set, as the table can have any number of columns. Is there a way to use some kind of loop or dynamic assignment so that I can pass any number of parameters as column names?</p>
  
  <p>I know that I can filter out only the columns I want to use, and just leave out the rest, but that doesn't work in my case. I need the stored procedure to NOT return some specific columns with sensitive data.</p>
  
  <p>I am using SQL Server 2008, ASP.NET MVC 4, and C# in my application.</p>