How would I return multiple values (say, a number and a string) from a user-defined function in SQL Server?
相关问题
- Bulk update SQL Server C#
- SQL to Parse a Key-Value String
- Get path of node in tree
- How to evaluate an input in the WHERE clause
- Delete all records in table which have no referenc
相关文章
- How to truncate seconds in TSQL?
- SQL identity (1,1) starting at 0
- SQL Group by Count of Counts
- How to generate sequential row number in tsql?
- Sql insert if row does not exist
- Pass table as parameter to SQLCLR TV-UDF
- Why not “Invalid column name XYZ” error in subquer
- Using Dapper-dot-net, how do I map SQL uniqueident
Example of using a stored procedure with multiple out parameters
As User
Mr. Brownstone
suggested you can use a stored procedure; to make it easy for all i created a minimalist example. First create a stored procedure:Calling the stored procedure
To execute the stored procedure a few local variables are needed to receive the value:
To see the values content you can do the following
This will be the result:
make it a table-valued function
see here http://technet.microsoft.com/en-us/library/ms191165.aspx , example included
Here's the Query Analyzer template for an in-line function - it returns 2 values by default:
Erland Sommarskog has an exhaustive post about passing data in SQL Server located here:
http://www.sommarskog.se/share_data.html
He covers SQL Server 2000, 2005, and 2008, and it should probably be read in its full detail as there is ample coverage of each method's advantages and drawbacks. However, here are the highlights of the article (frozen in time as of July 2015) for the sake of providing search terms that can be used to look greater details:
Another option would be to use a procedure with output parameters - Using a Stored Procedure with Output Parameters