sql server CLR scalar function with default column name

The answer is, "No." A scalar function (CLR or not) just returns a value.

"User-defined scalar functions return a single data value of the type defined in the RETURNS clause." per MSDN

As you suggested, the correct solution is adding an alias where you use the function.

SELECT ABS(a.Position - b.Position) AS Distance
    FROM sch.Tbl a
        INNER JOIN sch.Tbl b
            ON a.Key <= b.Key
;

And that doesn't change whether the function is a built-in, or a user-defined function, or a CLR function.


I assume somewhere you have a call to something like this:

command.CommandText = "SELECT SomeFunction();";

try this

command.CommandText = "SELECT SomeFunction() 'AliasForColumnNameYouWant';";

Not sure what you mean by 20 or 30 functions?

Are you saying that within Sql-Server there is some stored procedure or function calling 20 or 30 different scalar functions?

Or maybe the same function being called 20 or 30 times?

And are you combining the results into a returnable row or column of data?

Need code examples please.