See article: https://www.codeproject.com/Articles/1199648/Using-Stored-Procedure-User-Defined-Function-and-V