0

I am trying to generate data inserts that are filtered based on column data. We have no problems scripting out all of the data using the scripter.Options.ScriptData and using the EnumScript method. Our goal is to script out inserts for a result set.

Is there a way to do do this, or am I looking at it the wrong way?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
  • I don't understand what you mean by "script out inserts for a result set". A result set comes from a `SELECT` statement, so what do `INSERT`s have to do with it? Can you give a more specific example of what you want to do? – Pondlife May 01 '13 at 23:34
  • If I'm reading the poster's question correctly, it's something like this. Let's say he has a table that has 10 rows. He runs a select that produces 3 of those rows. He then wants a way to get back a result set that looks like `insert into dbo.tbl (a, b, c) values (1, 2, 3), (2, 3, 4), (3, 4, 5)` – Ben Thul May 02 '13 at 02:28
  • The scripter EnumScript method allows you to script out the schema (and optionally the data) and builds the create table statements and data inserts. Basically, I don't want it to script out the inserts for all of the data, but only a certain result set. – Christopher May 02 '13 at 12:59
  • So you want to script `INSERT` statements for a subset of the rows in the table? This has been [asked already](http://stackoverflow.com/questions/7317856/generating-script-for-subset-of-the-data) although unfortunately there are no answers, only a suggestion to use [this tool](http://www.ssmstoolspack.com/). I was going to suggest a view, but it seems that you [can't script data from a view](http://social.msdn.microsoft.com/Forums/en-US/sqlsmoanddmo/thread/e3ae4d19-2b47-46e8-be53-6549586c2516/) (probably for good reasons) so perhaps you can `SELECT...INTO...` a new table and script from that? – Pondlife May 02 '13 at 15:35
  • Correct Pondlife. We have SSMS Tools already but it is painfully slow. Additionally, my goal was to automate that process. I never thought of selecting into a new table. Thanks for a suggestion that should have been obvious. (I tend to over-think things.) – Christopher May 07 '13 at 19:34

0 Answers0