Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 SQL Server Development (2000)
 Payroll Processing

Author  Topic 

AskSQLTeam
Ask SQLTeam Question

0 Posts

Posted - 2006-05-30 : 09:26:22
Anand writes "I am doing a payroll processing, and it is done in batch process through a series of stored procedures.
I have a constraint where i cannot do it in a batch for all employees, hence I have to declare a cursor and loop through each employee and do the process. Here I am using a cursor, is it safe and do I have an alternative for the cursors in this case

Thanks in Advance"

TG
Master Smack Fu Yak Hacker

6065 Posts

Posted - 2006-05-30 : 10:36:45
Hi Anand,

>>Here I am using a cursor, is it safe and do I have an alternative for the cursors in this case
There is almost always a better, set-based alternative to using a cursor but it is impossible to be specific without more information from you. I suggest you register with sqlteam.com so you can respond to posts, then respond to this post with the entire SP code (that uses the cursor).

Here is a (very simple) example of replacing a cursor with a set-based solution:

--cursor
declare @pk int, @col1 int
declare crs cursor for
select pk, col1 from myTable where dtCol = 'myDate'
open crs
fetch next from crs into @pk, @col1
while @@fetch_status = 0
begin
update myOtherTable set
col1 = @col1
where pk = @pk

fetch next from crs into @pk, @col1
end
close crs
deallocate crs

--set based
update mt set
mt.col1 = mot.col1
from myTable mt
join myOtherTable mot
on mot.pk = mt.pk
where dtCol = 'myDate'


Be One with the Optimizer
TG
Go to Top of Page
   

- Advertisement -