help with cursor plz

  • So I have simple cursor

    DECLARE @au_user int, @au_event int, @au_bid float

    DECLARE bid_history CURSOR FOR

    SELECT UserID, EventID, CAST(TotalBidAmount as float) FROM Bids WHERE EventID in (262) group by eventid, userid, DTS, TotalBidAmount

    OPEN bid_history

    FETCH NEXT FROM bid_history

    INTO @au_user, @au_event, @au_bid

    WHILE @@FETCH_STATUS = 0

         BEGIN

              select @au_user, @au_event, @au_bid

              FETCH NEXT FROM bid_history

              INTO @au_user, @au_event, @au_bid

         END

    CLOSE bid_history

    DEALLOCATE bid_history

    which I'll change later - all those select statements will go into #Temp table later on... but anyway. This cursor doesn't do exactly what I need.

    It gives me result back as(for example):

    UserID       EventID       Amount

    100              8                XXX

    100              8                XXXX

    100              8               XXXXX

    101              8               NNNNN

    101             8                NNNNN

    so anyway, could be N amount of users who have bids, well I need result to have another column that would have Number of Bid for each user. So instead of Original I would get:

    UserID       EventID       Amount            BidNumber

    100              8                XXX                      1

    100              8                XXXX                    2

    100              8               XXXXX                   3

    101              8               NNNNN                   1

    101             8                NNNNN                   2

    How can I do that? If extra #temp table is needed it's fine - pretty much I need this done no matter how, even if it's ugly

  • You don't need the cursor to do the insert, check out this post. The last part of my first post would be the way to go (assuming you can't handle this task client side).

    Extended Challenge - Answer

  • got it to work w/o cursor. thanks all

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

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