sql - How to slow down cursor processing -


due programming limitations of odbc driver using set linked server in sql server, have use cursor process insert linked server odbc driver fails when attempting set-based insert.

the code using quite similar following:

set nocount on  declare curoutput cursor    select  qty, qb_item_id, qb_id, qb_flag                    dbo.qb_invoicelines                   qb_id not null             order    qb_id, qb_flag desc, transaction_type asc;  declare @quantity decimal(18,2), @itemid varchar(100), @customerid varchar(100), @qbflag int;  open    curoutput  fetch   next    curoutput    @quantity, @itemid, @customerid, @qbflag; --subroutine qb insert while @@fetch_status = 0     begin     insert remote...invoice_test (qb_id,qb_item_id,qty,qb_flag)         values(@customerid,@itemid,@quantity,@qbflag)     print   'transaction quantity of ' + cast(@quantity varchar(12)) +  '     item id ' + @itemid + ' customer id ' + @customerid + ' posted.'      fetch   next        curoutput        @quantity,         @itemid,         @customerid,         @qbflag; end --end subroutine qb insert close       curoutput deallocate  curoutput 

in processing records, @qbflag set either 1 or 0, 1 instructing odbc driver hold transactions in cache until 0 processed, @ time transactions posted linked server tables.

when using above method, driver hum along quite nicely several hundred rows (there typically 7500 - 9000 rows process), fail believe though cursor processing records 1 @ time still attempting write table faster linked table can handle transactions.

should use delay function or there better solution?

cheers! mike

you don't need cursor. can use simple insert query:

insert remote...invoice_test  (qb_id,qb_item_id,qty,qb_flag) select  qty, qb_item_id, qb_id, qb_flag dbo.qb_invoicelines qb_id not null 

Comments

Popular posts from this blog

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

html - How to style widget with post count different than without post count -

url rewriting - How to redirect a http POST with urlrewritefilter -