title: SQL Server - replace view with stored procedure
body: <p>I have a closed source ASP.NET system that is calling a very expensive SQL view:</p>
  
  <pre><code>SELECT TOP 100 PERCENT * 
  FROM [v]  
  WHERE [u] =  9999 
  ORDER BY [ID]
  </code></pre>
  
  <p>I have access to the database, so I can change the view - there is no easy way to make the view faster.</p>
  
  <p>I would like to programmatically change the behaviour of the view based on which IIS server is performing the request.</p>
  
  <p>Is this possible?</p>
  
  <p>E.g. I would like to create a stored procedure that would be called from the view, and this stored procedure would return a table that mimics the current view, but if called from a particular IIS server would return something different.</p>
  
  <p>Is it possible to modify the view to call a stored procedure so that the asp.net code doesn't need any modifications?</p>
  
  <p>I can see from other stack overflow articles how to call a stored procedure from a view, but how can I access the where clause inside the stored procedure?</p>