Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Return multiple values from a SQL Server function

How would I return multiple values (say, a number and a string) from a user-defined function in SQL Server?

like image 677
Jeremy Stein Avatar asked Nov 10 '08 20:11

Jeremy Stein


People also ask

How can I return multiple values from a 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.

Can you return multiple values from a function?

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.

Can a function have multiple return statements in SQL?

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.

How can I return multiple values in one column in SQL?

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.


1 Answers

Change it to a table-valued function

Please refer to the following link, for example.

like image 132
devio Avatar answered Sep 21 '22 12:09

devio