Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Database & SysAdmin
  3. Database
  4. anwhat's wrong with my cursor!!!!!!!!!

anwhat's wrong with my cursor!!!!!!!!!

Scheduled Pinned Locked Moved Database
announcementcareer
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • U Offline
    U Offline
    under2811
    wrote on last edited by
    #1

    :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

    C 1 Reply Last reply
    0
    • U under2811

      :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

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      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

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups