title: Using UPDATE in stored procedure with optional parameters
body: <p>I have an SP like so (using SQL Server):</p>
  
  <pre><code>ALTER PROCEDURE [dbo].[sp_ClientNotes_update]
      @id uniqueidentifier,
      @ordering smallint = NULL,
      @title nvarchar(20) = NULL,
      @content text = NULL
  AS
  BEGIN
      SET NOCOUNT ON;
      UPDATE tbl_ClientNotes
      SET ordering=@ordering, title=@title, content=@content
      WHERE id=@id
  END
  </code></pre>
  
  <p>I would like to only set the values if they are passed into the SP, i.e. not NULL. Can this be done?</p>
  
  <p><a href="https://stackoverflow.com/questions/2424244/how-to-handle-optional-parameters-in-a-update-stored-procedure">This question</a> seems to suggest the only way is using completely separate queries with conditionals, but for 3 optional parameters this would obviously be a nightmare!</p>