Access to Result sets from within Stored procedures Transact-SQL SQL Server

前端 未结 7 1192
栀梦
栀梦 2020-11-27 17:59

I\'m using SQL Server 2005, and I would like to know how to access different result sets from within transact-sql. The following stored procedure returns two result sets, ho

7条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-27 18:23

    There is a kludge that you can do as well. Add an optional parameter N int to your sproc. Default the value of N to -1. If the value of N is -1, then do every one of your selects. Otherwise, do the Nth select and only the Nth select.

    For example,

    if (N = -1 or N = 0)
        select ...
    
    if (N = -1 or N = 1)
        select ...
    

    The callers of your sproc who do not specify N will get a result set with more than one tables. If you need to extract one or more of these tables from another sproc, simply call your sproc specifying a value for N. You'll have to call the sproc one time for each table you wish to extract. Inefficient if you need more than one table from the result set, but it does work in pure TSQL.

提交回复
热议问题