How to create a cursor with select query

  • I want to create a cursor where it has  a select query.(select emp1,emp2 from employee)
    I want to get those columns Information from this cursor.

  • 1) WHY?!?!?! They're horribly inefficient.
    2) How to create a CURSOR You haven't given enough information, but this link will give you the basics.
    3) WHY?!?!?! They're horribly inefficient.

    Drew

    J. Drew Allen
    Business Intelligence Analyst
    Philadelphia, PA

  • This seems to be part of the problem from the following thread: https://www.sqlservercentral.com/Forums/1866309/Question-on-Outer-and-Inner-Cursor

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Hi mcfarlandparkway ,
    I hope you can use the code below as example of cursor:::

    Declare @emp1 varchar(20)

    Declare @emp2 varchar(20)

    Declare Mycursor cursor for

    Select * from employee

    open Mycursor

    fetch next from Mycursor into @emp1,@emp2

    while (@@FETCH_STATUS=0)

    begin

    Print @emp1 +' '+ @emp2

    fetch next from Mycursor into @emp1,@emp2

    end

    Close Mycursor

    Deallocate Mycursor

    Regards
    Anna

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply