title: Embed If Statement Inside Case
body: <p>How to embed and if statement inside a case. This is what I have so far.</p>
  
  <pre><code>DECLARE @LDCCode as int
         DECLARE @InvoiceDate as datetime
         DECLARE @PaymentSemiMonthlyDays AS int
         SET @LDCCode = 20
         SET @InvoiceDate = '5/16/2012'
         DECLARE @InvDateDayMonth AS INT
         DECLARE @ReturnDate AS DATETIME
         SET @ReturnDate = @InvoiceDate
         DECLARE @PaymentDOM AS INT
         DECLARE @PaymentDays AS INT
         DECLARE @PaymentSemiMonthlyOffset AS INT
  
  
  SET @ReturnDate = CASE WHEN NOT @PaymentDOM IS NULL THEN
     @ReturnDate + (@PaymentDOM - DATEPART(day, DateAdd(mm,1,@ReturnDate))) 
  WHEN NOT @PaymentDays IS NULL THEN 
              DATEADD(Day,@PaymentDays,@ReturnDate)
  WHEN NOT @PaymentSemiMonthlyOffset IS NULL THEN                     
      IF @LDCCode = 40 AND @InvDateDayMonth &gt; 11 AND @InvDateDayMonth &lt; 26 
         SELECT @ReturnDate + (@PaymentSemiMonthlyOffset - DATEPART(day, DateAdd(mm,1,@ReturnDate)))
      ELSE
         SELECT @ReturnDate + (@PaymentSemiMonthlyDays - DATEPART(day, DateAdd(mm,1,@ReturnDate)))    
      END 
  </code></pre>