title: Can I create create a global function in SQL Server?
body: <p>Is it possible to create a function in SQL Server which I could use in any database on the server, without adding the database prefix?</p>
  
  <p>For example, with this function:</p>
  
  <pre><code>CREATE FUNCTION getDays (@date date)
  RETURNS INT
  AS
  BEGIN
  
  RETURN CASE WHEN MONTH(@date) IN (1, 3, 5, 7, 8, 10, 12) THEN 31
              WHEN MONTH(@date) IN (4, 6, 9, 11) THEN 30
              ELSE CASE WHEN (YEAR(@date) % 4    = 0 AND
                              YEAR(@date) % 100 != 0) OR
                             (YEAR(@date) % 400  = 0)
                        THEN 29
                        ELSE 28
                   END
         END
  
  END
  </code></pre>