Missing Records After Cursor

  • I Have a Cursor that  Loops On  Some Records

    at the end of the cursor the records are beeing written to a table.

     

     

    I have tested the open cursor query agaunst a control query to validate that the data I want is beeing selected but at the result table I have missing records

     

    Does eny one have a speculation.

    I am not changing the data just adding to it .

  • Gil - you'll have to post your t-sql (or at least the portion that involves the cursor) for anyone to be able to troubleshoot this for you.

    You also stand to benefit from someone coming up with a (possible) cursor-less solution if you post your code!







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

  •  

    Hi,

    Don't ever use cursors.

    Use temp tables in place of that.

     

     

    ***** Have a nice day ********

    Regards,

    AMIT GUPTA

     

     

  • Don't take bad advice from strangers.

     

  • ..actually, it is...

    Don't take no for an answer!

    Don't accept candy from strangers...

    and

    Don't take bad advice from ANYBODY!!!







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

  • i am using table variables

    for example

    declare @tablecursor table ( [idi] [int] IDENTITY (1, 1) NOT NULL

    ,data varchar (255),

    processed bit default 0 )

    insert into @tablecursor select data from mytable

    select top 1 @idi = idi,

    @data = data,

    @processed = processed from @tablecursor where processed = 0

    while isnull(@processed,1) = 0

    begin

    ..........code of my cursor

    update @tablecursor set processed = 1 where idi = @idi

    select top 1 @idi = idi,

    @data = data,

    @processed = processed from @tablecursor where processed = 0

    end

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

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