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)
 Help on WHERE CURRENT OF USING CURSORS

Author  Topic 

vin
Starting Member

26 Posts

Posted - 2003-05-17 : 03:58:57
Hi,

I am using SQL server 2000, and facing one problem using cursors.
Can you any body tell me how to use WHERE CURRENT OF clause.
I am posting my sample code here

Declare
@Temp_emp_id varchar(9),
@Temp_job_id smallint

select @Temp_emp_id = null,
@Temp_job_id = 0

DECLARE emp_cursor CURSOR FOR
SELECT emp_id,job_ib
FROM emp
order by emp_id

OPEN emp_cursor
-- Perform the first fetch.
FETCH NEXT FROM emp_cursor into @Temp_emp_id, @Temp_job_id

WHILE @@FETCH_STATUS = 0
BEGIN
if (@Temp_job_id = 13)
begin
update emp
set processed = 1
--where current of emp.job_id
where job_id = @Temp_job_id
end
FETCH NEXT FROM emp_cursor into @Temp_emp_id,@Temp_job_id
END

CLOSE emp_cursor
DEALLOCATE emp_cursor

Error : Server: Msg 207, Level 16, State 3, Line 9
Invalid column name 'job_ib'.

The emp table contains Job_id column. The structure of emp is

emp_id varchar(9)
job_id samllint
processed tinyint

if some body help me how to resolve this.

Thanks & Regards
Vinay

robvolk
Most Valuable Yak

15732 Posts

Posted - 2003-05-17 : 07:32:50
How about:

UPDATE emp SET processed=1 WHERE job_id=13

You certainly don't need a cursor for a simple UPDATE like this.

Go to Top of Page
   

- Advertisement -