Click here to Skip to main content
15,890,882 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
SQL
declare @PhaseDate datetime
declare @DueDate datetime
declare @CUST_ID bigint
declare @FLAT_ID bigint
	DECLARE @toLast CURSOR
SET @toLast = CURSOR FOR
select FLAT_ID,CUST_ID,DueDate,PhaseDate from TBL_FLATMSTR where TOTAL_VALUE!=null
OPEN @toLast
FETCH NEXT
FROM @toLast INTO @FLAT_ID,@CUST_ID,@DueDate,@PhaseDate
WHILE @@FETCH_STATUS = 0
BEGIN

exec rptPhaseAllDeatils @PhaseDate ,@DueDate  ,@CUST_ID ,@FLAT_ID-- this query returning me temp table data like (select * from temp)
union--Here i want help
FETCH NEXT
FROM @toLast INTO @FLAT_ID,@CUST_ID,@DueDate,@PhaseDate
END
CLOSE @toLast
DEALLOCATE @toLast
END


every time i call rptPhaseAllDeatils proc i just flush all data and fill with new data
now i want all merge data
Posted
Updated 25-Jun-13 3:49am
v2

You might be better off changing your stored procedure to provide the extra data if (say) an additional parameter is set. Good comments on responses to this post http://stackoverflow.com/questions/5292069/union-the-results-of-multiple-stored-procedures[^]
Note that the union will only work if your SP returns bigint, bigint, datetime, datetime
 
Share this answer
 
I know this has already been solved, but I thought it might be educational to spell out the answer and an alternative approach.
DECLARE @PhaseDate DATETIME;
DECLARE @DueDate DATETIME;
DECLARE @CUST_ID BIGINT;
DECLARE @FLAT_ID BIGINT;

--Temporary table to accumulate the results into.
CREATE TABLE #holdingTable (
	PhaseDate DATETIME,
	DueDate DATETIME,
	CUST_ID BIGINT,
	FLAT_ID BIGINT
	--List the other columns returned from rptPhaseAllDeatils here.
	);

--Fast_forward cursors are faster than default ones.
DECLARE toLast CURSOR LOCAL FAST_FORWARD FOR
	SELECT FLAT_ID, CUST_ID, DueDate, PhaseDate
	FROM TBL_FLATMSTR
	WHERE TOTAL_VALUE != NULL;
OPEN toLast;

--The "WHILE(1 = 1) BEGIN ... FETCH ... IF (@@Fetch_Status > 0) BREAK" pattern
--means we don't need to repeat the FETCH statement (so less typing).
WHILE (1 = 1) BEGIN
	FETCH toLast INTO @FLAT_ID, @CUST_ID, @DueDate, @PhaseDate;
	IF (@@FETCH_STATUS > 0) BREAK;

	--Append output of "rptPhaseAllDeatils" sproc to our temporary table.
	INSERT INTO #holdingTable
		EXEC rptPhaseAllDeatils @PhaseDate, @DueDate, @CUST_ID, @FLAT_ID;
END
CLOSE toLast;
DEALLOCATE toLast;

--Return the accumulated results.
SELECT * FROM #holdingTable;

A faster alternative would be to create a new version of rptPhaseAllDeatils that incorporates the TOTAL_VALUE != NULL filter. That would be much faster than mucking about with a temporary table and a cursor.
 
Share this answer
 
Comments
CHill60 26-Jun-13 18:57pm    
Good expansion ... I was lazy :-)

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