Dude, Do it all in a query with unions. ie:
declare @tmp table ( id int identity(1,1), sumvalue numeric(12,2) ) insert into @tnp (sumvalue) select sum(column_x) from table_x union all select sum (column_y) from table_y select sum( sumvalue) from @tmp You can use the last select to put where ever you want. Hope this helps. AL On Fri, Feb 27, 2009 at 4:21 AM, pantagruel <[email protected]>wrote: > > Hi, > > I have a situation where I have a number of queries in a stack. The > number is generally 1, but it can theoretically be any amount. > > I need to execute the queries and then loop through the rows of each > query and then combine these results, the final combination is written > to a text file matching a particular archiving format. > The queries do not return the same nunber of columns or rows. > If query returns two rows 7 columns, query 2 returns 0 rows but has 4 > possible columns (if it did return anything), and query 3 returns 3 > rows 2 columns then the final output should be > > 3 rows 13 columns with the empty columns in the database replaced by > particular characters. > > Currently I have an algorithm that does my output if I have 1 query. > > what I was thinking was: > > loop through number of queries, make new data adapter, loop through > rows, read rows into some data structure where I can append a > particular result by an index, for example an array and then at the > end loop through that data structure and write it out. > > However I worry about that because of the potential size of what is > returned - say a couple MB is not an unwarranted expectation that the > choice of data structure becomes somewhat important. If I were to > follow this method what data structure do you think I should use? > > The application does not need to have any particular good performance, > but it can't crash under the strain of too much data either. > > Alternately if you can suggest something else that would be great, as > the method outlined above seems inefficient. Although the best I can > come up with under the constraints of the problem. > > Thanks > > >
