开发者

Set 5 variables from a temporal table return of function SQL Server

How to set 5 variables from a result of function in SQL Server, without creating other table

If there is a function that returns a table and I'm setting a var to a result where a condition satisfies aka. (@counter), how would I procede if I want to get 5 values from the temp table is created??

开发者_如何学JAVA
SELECT @var1 = items 
FROM dbo.FUNCTION()
WHERE itemindex =  @counter

SELECT @var1,@var2,@var3,@var4,@var5 = items FROM ... but I know this can not be done, any idea??


You cannot do this - a stored function can either return:

  • one single scalar value
  • a table of data

If you convert this to a stored procedure, you could define five output parameters for your call - that might work

CREATE PROCEDURE dbo.YourProc @InParam1 INT,
                              @OutParam1 INT OUTPUT,
                              @OutParam2 INT OUTPUT,
                              @OutParam3 INT OUTPUT,
                              @OutParam4 INT OUTPUT,
                              @OutParam5 INT OUTPUT
AS BEGIN
     ....
END
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜