Hi Samuel,
Thanks for the info. I tried your suggestion however it seems that the issue is being encountered when I set the return parameter to nvarchar(max).
I was trying to return a json file from a sql query using a function and obviously I wouldn't know the size of the return.
I guess, I have to revert back to good old structures.