• 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

    ______________________________________________________________________________
    How I want a drink, alcoholic of course, after the heavy lectures involving quantum mechanics.