I have 10 scripts all of them are similar except for the file name and table name. Each script does a bulk insert to 10 different tables from 10 different files. I want consolidate all the scripts to one. Is there a way to do this other than putting a GO at the end of each script? I've heard someone mentioning I can do dynamic sql but don't know how.
The GO statement is for working with a single file within SQL Server Management Studio query window to break the queries into discrete batches. It's not how I would look at putting scripts together. If anything it breaks them apart. Without seeing the code, I can't tell if dynamic SQL is a good solution or not. The concept of a well constructed dynamic SQL statement is that you're building a string with the query inside of it. You can still use parameters as long as you use sp_executesql which means you can see plan reuse. Here's the [books online entry on sp_executesql]. For such a general question, that's the best answer I can come up with. :