Cursor is Refreshing Data After Open

  • I have Written Cursor like

    DECLARE Cur_Data CURSOR FOR

    SELECT Column1, Column2 FROM Table1 WHERE Column3 = 1

    OPEN Cur_Data

    FETCH NEXT FROM Cur_Data

    WHILE @@FETCH_STATUS = 0

    BEGIN

    INSERT INTO TABLE1 (Column1,Column2,Column3)

    VALUES (Value1,Value2,1)

    FETCH NEXT FROM Cur_Data

    END

    This Loop is running indefinitely

    Afterward we come to know it is because it is always refreshing it & take data from table where condition matchs

    What can i do if i want to add same data using Cursor ??

    Thanks in Advance

  • Maybe you've over simplified the code you've posted, but I'd just replace all that with,

    INSERT INTO TABLE1 (Column1,Column2,Column3)
    SELECT Column1, Column2 FROM Table1 WHERE Column3 = 1

     

    --------------------
    Colt 45 - the original point and click interface

  • If you need to use cursor, then go for static cursor, that will not open the table anyway. It uses tempdb for its process.

  • If phill's right in his assumption of "oversimplification of code" then you should use his SQL - else Manish - it may be in your best interests to post what you actually want to do and someone is bound to come up with a better/faster/(& possibly) a cursorless way...







    **ASCII stupid question, get a stupid ANSI !!!**

  • "Cursorless"?  To cursor, or not to cursor.  That IS the question? 

     

    I wasn't born stupid - I had to study.

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

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