I'm sure this is pretty basic, but how do I set up an INSERT statement using a variable for the table name?
For example, I have a number of input files, all configured identically (Input1, Input2, Input3, ...) all going to an INSERT or MERGE statement.
I want to either do a loop, working through all the input files, or call the INSERT statement as a function
INSERT INTO [OutputFile]
SELECT i.*
FROM [<Input Variable>] i
LEFT JOIN [OutputFile] OP
ON CONCAT(i.Field1, i.Field6) = CONCAT(OP.Field1, OP.Field6)
WHERE OP.Field1 IS NULL
PRINT 'Number of rows added is ' + CAST(@@ROWCOUNT as char(6));
I'll actually be using MERGE statements, but I assume the process will be the same.