title: How to use IF statement in SQL Server 2005?
body: <p>This is the scenario I would like to have in my <code>INSERT</code> in a stored procedure.</p>
  
  <p>Tables:</p>
  
  <p><strong>tblRate</strong>  </p>
  
  <ul>
  <li>RateID (pk)    </li>
  <li>Rate money    </li>
  <li>Days int</li>
  <li>isDailyRate bit</li>
  </ul>
  
  <p><strong>tblBooking</strong></p>
  
  <ul>
  <li>Totals money</li>
  </ul>
  
  <p>In my vb app this is the statement. How would I translate this into T-SQL?</p>
  
  <pre><code> if !isDaily = True then
        !Totals = (!Days * !Rate)
   else
        !Totals = !Rate
   end if
  </code></pre>
  
  <p>This is my stored procedure:</p>
  
  <pre><code>Create PROCEDURE [dbo].[sp_tblBooking_Add] 
     (
      @RateID     bigint,
      @Rate       money,
      @Days       int,
      @CheckOUT   datetime
     )
  AS
  BEGIN
      --Below is the logic I want. I can't get the right syntax
  
      --Declare @myTotals as money
      --Declare @myCheckOut as DateTime
  
      --if (Select isDailyRate FROM tblRates WHERE (RateID = @RateID)) = True THEN
      --  set myTotals = (@Rate * @Days)
      --  set @CheckOUT   = DATEADD(DAY, DATEDIFF(DAY, 0, GETDATE()) + @Days, '12:00') 
      --Else
      --  set myTotals = @Rate
      --  set @CheckOUT   = GETDATE()
  
      --End if
  
      INSERT INTO tblBooking(Totals, CheckOUT)
      VALUES(@myTotals, @myCheckOut); 
  END
  </code></pre>