Groups | Blog | Home
all groups > sql server clustering > november 2004 >

sql server clustering : How to run my Curser more faster?


raj
11/28/2004 4:15:03 PM
I have a stored procedure written for number of updates, inserts to the
database. This stored procedure takes too long to run. I have created few
indexes around few tables, but the response time is not that defferent.
THere is a Curser "CURSOR FAST_FORWARD FOR" in the stored procedure, and
another stored procedure is called within this Curser. I found that lot of
time been taken to run this Curser. So I want to run/make it faster the
curser. So how should I improve the Curser to run more faster
I would greatly appreciate anyone's idea or suggesions.

thanks

raj
11/28/2004 5:29:02 PM
this is the part of the query takes too long to run
---------------------------------------------------

BEGIN
DECLARE CustCursor CURSOR FAST_FORWARD FOR
SELECT DISTINCT D.CustID FROM tblInv D INNER JOIN #Invoice I ON D.InvID =
I.InvID
OPEN CustCursor
FETCH NEXT FROM CustCursor INTO @CustID
WHILE (@@FETCH_STATUS <> -1)
BEGIN
EXEC sp_UpdateDunning @CustID
IF @@Error <> 0
BEGIN
CLOSE CustCursor
DEALLOCATE CustCursor
ROLLBACK
RAISERROR('Error executing - > sp_UpdateDunning.', 16, 1)
RETURN
END
FETCH NEXT FROM CustCursor INTO @CustID
END

CLOSE CustCursor
DEALLOCATE CustCursor
END

----------------------------------------------------------------------
All the tables involved in this curser, indexes have been created.

raj


[quoted text, click to view]
Alfred XYZ
11/29/2004 1:05:04 AM
The following approach would sacrify the transactional
opertion on the batch, but is likely the fast.

-- ===============
-- Run the script at QA
-- ===============
declare @CustID int, @cmd varchar(255)
delcare tmp_cur cursor for
select distinct D.CustID
from tblInv D inner join #Invoice I
on D.InvID = I.InvID
open tmp_cur
fetch next from tmp_cur into @CustID
while @@fetch_status = 0
begin
select @cmd = 'exec sp_UpdateDunning ' + convert
(varchar, @CustID)
print @cmd
print 'go'
fetch next from tmp_cur into @CustID
end
close tmp_cur
deallocate tmp_cur

-- ===============
-- Run the result of script at QA
-- ===============
For example:
exec sp_UpdateDunning 1
go
exec sp_UpdateDunning 2
go
....

^^
Regards,
Alfred

[quoted text, click to view]
Greg D. Moore (Strider)
11/29/2004 1:18:13 AM

[quoted text, click to view]

Best Advice: Eliminate the Cursor.

But, without a DDL and some sample table folks here won't be able to help
you with that.

So, if you can, post your DDL and some data and see what folks can do.


[quoted text, click to view]

AddThis Social Bookmark Button