8

Is it possible to overload a sql server function? Either a scalar, like ltrim, or an aggregate function, like count?

Even if this was a really, really, bad idea. Is it possible?

Somewhat of a duplicate of T-SQL User defined function overloading? I would say it isn't 100% a duplicate, since that was for 2005 version. Maybe this has changed?

10

There is no straight-forward way of carte-blanche overriding a built-in function in SQL Server.

You can kind of fake it by creating a function with the same name in a different schema, then calling that function with the schema name, as in:

SELECT dbo.COUNT(1)
FROM dbo.SomeTable st
GROUP BY st.SomeCol;

However, this is quite likely to cause more confusion than it is worth.

  • 5
    And if you're going to have to change the code to use the schema name anyway, you might as well change it to refer to a differently-named user function. – BradC Jul 5 '18 at 15:07
  • 1
    Completely agree, @BradC - overall it's just a bad idea to try overloading in SQL Server. – Max Vernon Jul 5 '18 at 15:15

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.