What is Cursor in sql server
  • Thank You
    Regards,
    M.Hussain
    Software Engineer
  • 2 Comments sorted by
  • Hi Hussain.
    Cursor is use to manipulate data row by row on resultset like we use datatable in c#.You can apply your logic on single row basis you can see very basic example below.

    In this discussion I describe how to use loop in sql

    Declare @Felid1 as varchar(50)
    Declare @Felid2 as varchar(50)
    Declare @Felid3 as varchar(50)

    Declare mycur cursor for

    Select Felid1,Feild2,Feild3 from tablename
    open mycur
    Fetch Next from mycur into @Felid1,@Feild2,@Felid3
    While @@FetchStatus=0
    Begin
    if @Felid1="a"
    Begin
    print @Felid2 
    /*User can put his logic or programing in it*/
    End
    Fetch Next from mycur into @Felid1,@Feild2,@Felid3
    End

    above example copy from this link http://codingresolved.com/discussion/170#Item_1
  • in simple word cursor is like a pointer in sql which read value row by row like record set in c# or vb.net
    for further details and related topics http://www.codecorner.somee.com/

Howdy, Stranger!

It looks like you're new here. If you want to get involved, or you want to Ask a new Question, Please Login or Create a new Account by Clicking below

Login with Facebook

Popular Posts of the Week

Top Posters Weekly

Optimum Creative