Leveraging Expressions in a Custom SQL Server Function

SQL Server offers several built-in string functions, like RIGHT(), which can take an expression as its argument—this means they work with both varchar and nvarchar inputs.

I want to develop my own user-defined function with similar capabilities. Could someone illustrate the basic syntax and provide a simple example to guide me through this process? I’m not very experienced in SQL Server, so a straightforward demonstration would be very helpful.

Thanks in advance for any assistance.

hey, try making a function that accepts a string param and uses substring() inside to return part of it. i did a similar thing for a project and had to double-check data types and null cases. hope it gives u a head start

hey, i built a udf like that and found make sure your datatypes match isn’t overrated. did u try combinations with cast or convert? im curious if u ran into any perf issues when using expressions inside the function?