title: Create View based on condition in SQL Server
body: <p>This question is asked several times, but I cann't figure out some things.</p>
  
  <p>First, I have situation that I need to create view (must be view), but according to the result of one query.</p>
  
  <pre><code>create view as
  if (select count(oid)...)&gt;1
     select1
  else
     select2
  </code></pre>
  
  <p>I know that this form is not allowed. But how can I accomplish something like this? I have tens of views like this I need to create. Because these SELECT statements contain spatial conditions, and the database is big and has many many tables, I need the 'most optimal' solution, or it will query forever.</p>
  
  <p>I read something about using stored procedures and UD functions, but how to create view from them and get max performances?
  I don't need parameters in it, just way to create views defined by this condition.</p>