title: SQL Server 2012 - Unable to drop User Defined function
body: <p>The following syntax successfully creates a user defined function, but does not drop it. Can anyone identify where my error is?</p>
  
  <p>-- Example 1 - scalar function</p>
  
  <pre><code>USE AdventureWorks2012
  GO
  
  CREATE FUNCTION Sales.uf_MostRecentCustomerOrderDate (@CustomerID int)
  RETURNS
     DATETIME
  AS
  BEGIN;
      DECLARE @MostRecentOrderDate datetime;
  
      SELECT @MostRecentOrderDate = MAX(OrderDate)
      FROM Sales.SalesOrderHeader as soh
      Where CustomerID = @CustomerID
  RETURN @MostRecentOrderDate
  END;
  GO
  
  -- Using user defined scalar function
  SELECT Sales.uf_MostRecentCustomerOrderDate(29825); -- returns 2008-04-01 00:00:00.000 
  
  -- Delete existing scalar valued function
  USE AdventureWorks2012;
  GO
  
  -- determines if function exists in database
  IF OBJECT_ID (N'Sales.uf_MostRecentCustomerOrderDate', N'IF') IS NOT NULL
      -- deletes function
      DROP FUNCTION Sales.uf_MostRecentCustomerOrderDate;
  GO
  </code></pre>