I have problem with "returning" one procedure result to another procedure.
Description:
For example we have complex SELECT with parameters putted in one procedure.
USE [myDB]
GO
ALTER PROCEDURE dbo.Procedure1 @today date
AS
SELECT * FROM complex_query
now it's returning a lot of columns and numbers of columns and rows depends on @today value.
No I want to use result of Procedure1 in Procedure2
USE [myDB]
GO
DECLARE @cntMonth INT = 0;
WHILE @cntMonth < 12
BEGIN
SELECT x,y,z FROM result_of_Procedure1
SET @cntMonth = @cntMonth + 1;
END;
why I want it like that?
It's because the software I'm working on is connecting to DB, run procedure and get the result to frontend. So I have to code all the way in SQL.
So assuming software is doing one-time connection I don't want to got through Procedure1 every time WHILE statement is executed. How can I store the effect of Procedure1 to use it through Procedure2 while loop and prevent multiple runs of Procedure1?