Click here to Skip to main content
15,887,485 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
I have a stored procedure that returns three rowsets. The stored procedure is:
SQL
USE [AVAA]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
ALTER PROCEDURE [dbo].[SPGetDate]
AS
BEGIN
    SELECT * from tblAVAA;
    SELECT * from tblKit;
    SELECT GETDATE();
END
On exec [dbo].[SPGetDate], it is returning me three rowset which is as needed, but in another stored procedure, i only want value from second rowset, i.e. tblKit using exec [dbo].[SPGetDate].. Is there any key word to be added on exec [dbo].[SPGetDate] so that it will give me only second rowset??
Please do not give me a suggestion of directly entering SELECT * from tblKit; in my required SP because this is just an example of my actual requirement.
Any help???
Thanks in advance
Posted
Updated 25-Jun-15 6:59am
v2

1 solution

You can alter the SP to pass parameter(s) indicating which results you want. E.g.
ALTER PROCEDURE [dbo].[SPGetDate]
	@Param1 int, 
	@Param2 int, 
	@Param3 int
AS
BEGIN
	IF @Param1 = 1
		SELECT * from tblAVAA;
	IF @Param2 = 1
		SELECT * from tblKit;
	IF @Param3 = 1
		SELECT GETDATE();
END
GO
called like this
exec [dbo].[SPGetDate] 0,1,0
Or you could have a single parameter and use bitwise comparison e.g.
SQL
ALTER PROCEDURE [dbo].[SPGetDate]
    @Param1 int
AS
BEGIN
    IF @Param1 & 1 = 1
        SELECT * from tblAVAA;
    IF @Param1 & 2 = 2
        SELECT * from tblKit;
    IF @Param1 & 4 = 4
        SELECT GETDATE();
END
GO
which could be called like this (note the variables are just to make it obvious which resultsets are required)
SQL
declare @RS1 int = 1
declare @RS2 int = 2
declare @RS3 int = 4

exec [dbo].[SPGetDate] @rs2 -- 2nd recordset only
or
SQL
declare @reports int = @RS1 + @RS3
exec [dbo].[SPGetDate] @reports --1st and 3rd recordsets only

Alternatively just discard the other data in your other SP
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900