Iterating through query results

  • I need to make updates/inserts/deletes to a database based on one of the values retrieved. 

    For instance:

    Select Flag, MemberID, LastName, FirstName FROM #tmpTable

    The Flag value will be either an 'A', 'C', or 'D'.

    If it is an 'A' I need to insert that row into a table.  If it is a 'C' I need to make an update to a table.  If it is a 'D' I need to delete that row from a table.  All of this without a cursor

    Any help would be appreciated.

  • insert into TableA

    select flag, memberid, ...

    from #tmptable

    where flag = 'A'

    update tableb

    set x = y

    from #tmptable

    where flag = 'C'

    etc.

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

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