Meta

Generate INSERT statements from SQL Server

The original version of this code comes from here. That version, however, didn’t handle NULLs and just inserted empty strings or zeros. In the comments there was an updated version by spider_pat that supported NULL values but had a couple of problems, namely it only had one column to INSERT into (due to placing code inside of a loop instead of outside) and it didn’t enclose columns in brackets. The first was really easy to fix and the second most people probably don’t care about unless you have some system that automatically creates table names and you can’t rename them. Also, I took a little bit of time to clean up the code to make it more readable. Yes, I removed BEGIN/END blocks from single-statement IFs which I generally recommend against but this made it much easier to read.