sql server - How to execute sql scripts from a staging table in sql stored procedure -


what best approaches below scenario?

in c# program, have sql commands such update, insert, delete. execute them in c# program (which works fine) need execute these sql commands when 1 of stored procedure comes last line. planning store sql commands in staging table in same database , open table within stored procedure , execute 1 one.

what best approach in terms of opening table within stored procedure , traversing through table based on condition (like select * tempstagingtable customerid = '1000'). if returns 10 records, loop them , execute sql command stored in column named "customsqlscript"

ps: using sql 2008 r2.

well, can select data table initially, , instead of using cursor can use while loop(as increase performance compared cursor) , can execute predefined sql statement table b

please find below sql scripts same

please note: have not made use of relation,this plain example

create table test1(   customsqlscripts varchar(100) )  create table test2(  customer_id int primary key ,  first_name varchar(100),  last_name  varchar(100) )   insert test1 values('select first_name test2 customer_id=')  insert test2 values('1','rohit','tiwari')   declare @count int  declare @icount int=0  declare @dummysql varchar(100)   select @count= count(*)   test2   last_name='tiwari'   while(@icount<@count)  begin   select @dummysql =customsqlscripts    test1   set @dummysql=@dummysql+'1'   exec (@dummysql)   set @icount=@icount+1  end 

Comments

Popular posts from this blog

java - Run a .jar on Heroku -

java - Jtable duplicate Rows -

validation - How to pass paramaters like unix into windows batch file -