title: Writing a dynamic where clause in a stored procedure
body: <p>Hi i have a stored procedure which will have a dynamic clause, this is what my stored procedure looks like;</p>
  
  <pre><code>SELECT  Comment.AddDate,Event.StartTime,Users.Name
  FROM Comment
  JOIN Users on Users.USERS_ID  = Comment.UserID
  JOIN Event ON Users.USERS_ID = Event.UserID
  </code></pre>
  
  <p>If i pass a variable @Name the stored procedure should then look like this;</p>
  
  <pre><code>SELECT  Comment.AddDate,Event.StartTime,Users.Name
  FROM Comment
  JOIN Users on Users.USERS_ID  = Comment.UserID
  JOIN Event ON Users.USERS_ID = Event.UserID
  WHERE Name = @Name
  </code></pre>
  
  <p>However there are cases whereby the @Name i pass in will be empty, which means i want everything returned and not based on a specific name.</p>
  
  <p>Also in some cases i will also pass in an eventid, how do i go about doing this?</p>