• toddasd (12/5/2012)


    Change to

    declare @q varchar(max)

    SELECT @q = ISNULL(@q, '') + 'DELETE FROM ' + tablename + ' where tid =' + convert(char,rowid) + '; ' from #incoming where action = 0

    exec(@q)

    but beware the dangers of this type of dynamic sql.

    Edit: Read about the dangers here http://www.sommarskog.se/dynamic_sql.html

    This appears to be deleting everything from #incoming

    Whereas it should not have deleted the below row as action != 0

    4#test11111