| re: INSERT INTO Query
Before doing anything else, here are some considerations:
1. Are the columns on your generic table have the same names with that of your source table?
2. When you say that there are cases that your source table sometimes have fewer columns, do you mean any columns could be missing or just the right most?
It would be easier if your target and source table have the same column names. If this is the case you could do this:
1. Get the column names of your source table and store it as a comma delimited string/varchar. Let's say you use a variable called @ColumnNames
2. Build a dynamic query that will look like:
EXEC ('INSERT INTO TARGET_TABLE (' + @ColumnNames + ') SELECT ' + @ColumnNames + ' FROM SOURCE_TABLE ')
Then you are sure that your source table will always fit your target table, with respect to number of columns (not the size of each).
Good luck
-- CK
|