This is a Free Download
This is my most-downloaded item ever, with the CodeProject article I wrote to go with it having had 50,000+ visitors so far - and climbing.
What this incredible useful little script does is generate a series of insert or update statements for the rows in a table. It's very useful when you just want to copy a bit of data from a table in database to another.
It's also useful for creating data migration scripts if you're developing and just about anything else. I guarantee a permanent spot in your favourites folder, and I update it all the time as I make it jump through increasingly more difficult hoops. It's also a candidate for code obfuscation awards, so if you are up for a challenge try and work out the logic
Instructions : download the zip file, extract the script. Change the table name, select insert or update and run the script. You'll have a big list of insert or update statements for every row in that table (or, if you specify a where clause, you can filter the rows).
Nothing could be easier!
FAQ
Q: I've got no values from the script, what's wrong
A: You've probably got the table name wrong, are running against the master database, or some other table-name matching problem. You've got to put the table name in exactly as it is listed on the system catalog. To check, run a 'select * from sysobjects where name like 'yourname%' ' to find if you have the name correct.
Q: Why isn't this in a stored procedure. X has a similar script in a stored procedure. You should have yours in a stored procedure. I demand you put this in a stored procedure! (etc...)
A: It's not in a stored procedure because it is a hit-and-run quick script to generate statements, not part of a permanent system. If you're thinking of putting this in a stored procedure, you're probably thinking of making it a permanent feature of some system - which you should never do. This is a memory and tempdb intensive script which is designed to be run on the odd occasion. If you're thinking of using it on a regular basis to perform some function in your system : don't. Think about the problem you're solving from a different angle.
That said, if you want to make it into a stored procedure as part of a dev box script generating system or something, then go right ahead and encapsulate the script in a 'create procedure xxx '