Execute saved queries in table SQL Server -
i have table list of select statements:
query ---------------------------- select max(acc),min(acc) my_table1 select max(acc),min(acc) my_table2 select max(acc),min(acc) my_table3 .......
i want execute saved queries in table , save result in new table. because result should matches(max , min).
use cursor on table , execute dynamic t-sql adding insert into
@ beginning of every value sql statement.
create table tselect ( query varchar(1000) ); insert tselect values ('select max(acc),min(acc) my_table1') create table result (min int, max int); begin declare @stmt varchar(1000); declare db_cursor cursor select * tselect; open db_cursor fetch next db_cursor @stmt while @@fetch_status = 0 begin exec('insert result ' + @stmt); fetch next db_cursor @stmt end close db_cursor deallocate db_cursor end;
Comments
Post a Comment