title: Inner join with if statement
body: <p>I am trying to build the following sp :</p>
  
  <pre><code>USE [MarMoniApp]
  GO
  /****** Object:  StoredProcedure [dbo].[Desc_by_date]    Script Date: 10/23/2012     09:01:40 ******/
  SET ANSI_NULLS ON
  GO
  SET QUOTED_IDENTIFIER ON
  GO
  ALTER PROCEDURE [dbo].[Desc_by_date]
  @DateToSearch varchar(50)
  AS
  BEGIN
  select a.ticker,a.First_T, a.Last_T, a.Size_mln, a.pct_d_vol,a.a_trad,a.coolname,a.recency,b.Analyst
  from Order_Desc a
  
  CASE
  When a.coolname = 'ELTORO'
  then (Inner join MarMoniApp.dbo.Namelist b on a.ticker = b.ticker )
  END
  
  where convert(datetime, cast(rtrim(First_T) AS nvarchar)) &gt; DateToSearch 
  order by  CONVERT(DATETIME, cast(rtrim(First_T) AS nvarchar) )  DESC
  END
  </code></pre>
  
  <p>I want to do the inner join only if the "coolname" is equal to eltoro, but it seems that my syntax is not correct.</p>