desperateUser
Technical User
Hello, long time no talk to. Y'all have helped me out so much in the past that I haven't had any problems lately...well, til this one.
This SQL programming was written by someone else. I have the ability to change it - I just don't know what to do with it. This piece of a stored procedure has slowed to a crawl (90 minutes + to run all the way. When I first started working here it took maybe five minutes.) It is updating the description field of a list of accounts.
I would like to be pointed in the right direction as far as where to go from here. TIA.
This SQL programming was written by someone else. I have the ability to change it - I just don't know what to do with it. This piece of a stored procedure has slowed to a crawl (90 minutes + to run all the way. When I first started working here it took maybe five minutes.) It is updating the description field of a list of accounts.
Code:
/************************************************************************************************
Function : UPDATE - update any/all rows in the permanent table
************************************************************************************************/
update_record:
-- declare and open the temp table cursor
declare temp_tbl_crsr cursor scroll
for
select t.fund_id, t.account_id, t.center_id, t.center_desc
from dbo.ibiscen i INNER JOIN dbo.temp_ibiscen t
on i.fund_id = t.fund_id and i.account_id = t.account_id and i.center_id = t.center_id and
i.center_desc <> t.center_desc
-- declare and open the perm table cursor FOR UPDATE
declare perm_tbl_crsr cursor dynamic
for
select fund_id, account_id, center_id, center_desc
from dbo.ibiscen
for UPDATE of account_id, center_id, center_desc
-- open the cursors
open perm_tbl_crsr
open temp_tbl_crsr
-- get the first row from the temp_tbl cursor
fetch first from temp_tbl_crsr into @fund, @account, @center_id, @center_desc
-- loop through the rows in the cursor */
while @@fetch_status = 0
begin
-- get the first row from the prem_tbl cursor
fetch first from perm_tbl_crsr into @fund_p, @account_p, @center_id_p, @center_desc_p
-- loop through the rows in the cursor
while @@fetch_status = 0
begin if @fund + @account + @center_id = @fund_p + @account_p + @center_id_p
begin
if @center_desc <> @center_desc_p
begin
exec usp_ins_code_table_modifications "ibiscen","UPDATE","",
"center_desc", @center_desc_p, @center_desc
end
update ibiscen
set au = Left(RTrim(@center_id),3),
center_desc = @center_desc,
last_modified =CONVERT(char(11),getdate())
where fund_id + account_id + center_id = @fund + @account + @center_id
end
-- get the first row from prem_aufund cursor
fetch next from perm_tbl_crsr into @fund_p, @account_p, @center_id_p, @center_desc_p
end
-- get the next row from temp_tbl_crsr
fetch next from temp_tbl_crsr INTO @fund, @account, @center_id, @center_desc
end
-- close cursors
close temp_tbl_crsr
deallocate temp_tbl_crsr
close perm_tbl_crsr
deallocate perm_tbl_crsr
RETURN
I would like to be pointed in the right direction as far as where to go from here. TIA.