title: T-SQL use different WHERE clause based on value of input parameter
body: <p>I would like to change the <code>WHERE</code> clause of a query based upon the value of an input parameter. I'm guessing this is possible, but it seems that I'm approaching it in the wrong way? </p>
  
  <p>A simplified version on my SP query:</p>
  
  <pre><code>CREATE PROCEDURE [dbo].[GetMailboxMessagesByStatus]
      @UserId             UNIQUEIDENTIFIER,
      @MessageStatus      INT
  AS
  BEGIN
      SELECT  * 
      FROM  MailboxMessages m
      WHERE
      CASE @MessageStatus
          WHEN 4 THEN m.SenderId = @UserId    --Sent
          ELSE m.RecipientId = @UserId        --Inbox
      END
  END 
  GO
  </code></pre>