• It looks like I forgot to add the dynamic SQL that puts all these pieces together.

    -- Piece together everything into a single dynamic INSERT statement

    SET @SQL = 'INSERT INTO Stage.DATA_CHANGES (Tablename, Action, Key_Fields, Key_Values, Changes) SELECT * FROM (SELECT ''' +

    @p_changes_tablename + ''' tname, ''UPDATE'' action, ''' + @Key_Fields + ''' kfields, ' + @Key_Values + ' kvalues, ' +

    @Changes + ' Changes ' + @From + ' WHERE ' + @Join_Keys +

    ') alias1 WHERE len(replace(changes,''~'','''')) > 0'

    -- Run the dynamic SQL to populate the staging table

    EXECUTE (@SQL )

    As for the "Tally" table, that is just a table of numbers. The idea for this can be found by searching this forum for "tally table" or try [/url]

    Hopefully this helps. I would be interested to know if you, or anyone else, gets any use out of this. Good luck.