anwhat's wrong with my cursor!!!!!!!!!
-
:sigh:Hello I have empt table where job_id is field in it. I want to update empt table if job_id = '1' or '3' by '999' And if job_id not '1' or '3' then update by '456' So what's wrong with my cursor T.I.A Shashank ----------------------------------------------------- CREATE procedure lnt.textt @qurstr varchar(10) AS Declare @in AS Varchar(10) Declare crs_cc cursor for select job_id from empt FOR UPDATE OF job_id open crs_cc fetch next from crs_cc INTO @in while @@fetch_status = 0 IF @qurstr = '1' OR @qurstr = '3' BEGIN UPDATE empt set job_id = '999' where job_id = @qurstr print 'U Miss By Miles!!!!' print @qurstr END IF @qurstr IN (SELECT job_id from empt where job_id not in ('1','3')) BEGIN update empt set job_id = '456' where job_id = @qurstr print ' Success' END FETCH NEXT FROM crs_cc CLOSE crs_cc DEALLOCATE crs_cc GO
-
:sigh:Hello I have empt table where job_id is field in it. I want to update empt table if job_id = '1' or '3' by '999' And if job_id not '1' or '3' then update by '456' So what's wrong with my cursor T.I.A Shashank ----------------------------------------------------- CREATE procedure lnt.textt @qurstr varchar(10) AS Declare @in AS Varchar(10) Declare crs_cc cursor for select job_id from empt FOR UPDATE OF job_id open crs_cc fetch next from crs_cc INTO @in while @@fetch_status = 0 IF @qurstr = '1' OR @qurstr = '3' BEGIN UPDATE empt set job_id = '999' where job_id = @qurstr print 'U Miss By Miles!!!!' print @qurstr END IF @qurstr IN (SELECT job_id from empt where job_id not in ('1','3')) BEGIN update empt set job_id = '456' where job_id = @qurstr print ' Success' END FETCH NEXT FROM crs_cc CLOSE crs_cc DEALLOCATE crs_cc GO
I don't understand what you are trying to do with your code, but from your description at the top the update can be done much much faster without a cursor.
UPDATE empt
SET job_id = '999'
WHERE job_id IN ('1', '3')UPDATE empt
SET job_id = '456'
WHERE job_id NOT IN ('1', '3')
My: Blog | Photos WDevs.com - Open Source Code Hosting, Blogs, FTP, Mail and More