• HanShi (7/1/2013)


    erikd (6/26/2013)


    , but I wanted to try it without a cursor to build the column list.

    The code you posted in the first post does NOT contain a cursor. It does contain dynamic SQL, but you can't get passed that if you want to use this code for transferring data from different tables. The multiple SET REPLACE statements could be combined into one single statement, but that doesn't improve readability nor does it improve performance.

    So your approach is correct if you want to be flexible with your code. Keep in mind that DDL changes on the source needs to be replicated to the target. Your code will brake if the table definition on the source has columns that aren't present in the table definition on the target.

    I use the SET/REPLACE statements because when I try to hash out the correct number and placement of single quotes in things like this, I usually end up with a twitch.