sql - How to recursively update a table with a stored procedure -


i have stored procedure selects data in different format original table:

use [voltracker] go  declare @return_value int,         @offset int  set @offset = 5  while @offset >= 1 begin     exec    @return_value = [dbo].[sp_getstats]             @doffset = @offset,             @starttime = --some datetime,             @endtime = --some later datetime,             @contract = null      set @offset = @offset - 1 end  go 

this specific example selects 5 of tables properly. however, of these tables joined 1 table. how might go doing this?

create table variable matches schema of resultset returned sp_getstats. then, insert variable within loop:

... declare @stage table (yourcolumn1 varchar(10), yourcolumn2 int, ...);  while @offset >= 1 begin     insert @stage         exec    @return_value = [dbo].[sp_getstats]                 @doffset = @offset,                 @starttime = --some datetime,                 @endtime = --some later datetime,                 @contract = null      set @offset = @offset - 1 end  select * @stage; 

the above work return union of resultsets returned, if possible modify procedure (or create new one) can return complete set without loop suggest doing do.


Comments

Popular posts from this blog

blackberry 10 - how to add multiple markers on the google map just by url? -

php - guestbook returning database data to flash -

delphi - Dynamic file type icon -