How would I return multiple values (say, a number and a string) from a user-defined function in SQL Server?
Generally SQL Server functions will return only one parameter value if we want to return multiple values from function then we need to send multiple values in table format by using table valued functions.
We can return more than one values from a function by using the method called “call by address”, or “call by reference”. In the invoker function, we will use two variables to store the results, and the function will take pointer type data.
A function can have as many RETURN statements as you want. E.g. Below there are three. When the flow of control encounters a return statement then execution of the function stops and the value is returned.
You can either loop through the rows with a cursor and append to a field in a temp table, or you could use the COALESCE function to concatenate the fields.
Change it to a table-valued function
Please refer to the following link, for example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With