Sql-server – Is it Possible to Overload SQL Server Functions

functionssql server

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?

Best Answer

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:

FROM dbo.SomeTable st
GROUP BY st.SomeCol;

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