title: Alter a SQL server function to accept new optional parameter
body: <p>I already have a function in SQL Server 2005 as:</p>
  
  <pre><code>ALTER function [dbo].[fCalculateEstimateDate] (@vWorkOrderID numeric)
  Returns varchar(100)  AS
  Begin
    &lt;Function Body&gt;
  End
  </code></pre>
  
  <p>I want to modify this function to accept addition optional parameter @ToDate. I am going to add logic in function if @Todate Provided then do something else continue with existing code.</p>
  
  <p>I modified the function as:</p>
  
  <pre><code>ALTER function [dbo].[fCalculateEstimateDate] (@vWorkOrderID numeric,@ToDate DateTime=null)
  Returns varchar(100)  AS
  Begin
    &lt;Function Body&gt;
  End
  </code></pre>
  
  <p>Now I can call function as:</p>
  
  <pre><code>SELECT dbo.fCalculateEstimateDate(647,GETDATE())
  </code></pre>
  
  <p>But it gives error on following call:</p>
  
  <pre><code>SELECT dbo.fCalculateEstimateDate(647)
  </code></pre>
  
  <p>as</p>
  
  <blockquote>
    <p>An insufficient number of arguments were supplied for the procedure or
    function dbo.fCalculateEstimateDate.</p>
  </blockquote>
  
  <p>which as per my understanding should not happen.</p>
  
  <p>Am I missing anything?
  Thanks in advance.</p>