title: IF ELSE condition in SQL select
body: <p>I want to do a if-else condition statement in SQL Server but am not sure how.</p>
  
  <p>Inside the stored procedure I have the following parameters:</p>
  
  <pre><code>@MarketId nvarchar (10),
  @RegionId nvarchar (10)
  </code></pre>
  
  <p>And the following statement:</p>
  
  <pre><code>select * from Interaction I
  where 
  (@MarketId = 0 ) OR (I.MarketId = (SELECT Id FROM Market WHERE ExternalId = @MarketId))
  </code></pre>
  
  <p>What I want to do is to check the value of <code>@MarketId</code></p>
  
  <pre><code>if @MarketId = 0
  </code></pre>
  
  <p>then I want the where condition for <code>I.MarketId</code> to get its Ids from elsewhere like </p>
  
  <pre><code>(SELECT ID FROM Market WHERE ExternalId = @RegionId)
  </code></pre>
  
  <p>otherwise, if its 1, then I just want to leave it as is and get the Id from <code>@MarketId</code> instead of <code>@RegionId</code>..</p>
  
  <p>How should I go about this?</p>
  
  <p>Thanks!</p>