Wednesday, March 7, 2012

Generate SQL Query for Data?

We're using Sql Server 2000. Is there some way to generate SQL query output of my table data. So an output that looks something like:

INSERT INTO mytable (id, col1, col2) VALUES (1,'a','b');
INSERT INTO mytable (id, col1, col2) VALUES (2,'c','d');

Code Snippet

select 'Insert into MyTable(Id,Col1,Col2) values (' + convert(varchar,ID) + ',''' + col1 + ''',''' + col2 + ''');'

from <MyTable>

|||If you are looking for a way to script INSERT statements for your data, look at this:

http://vyaskn.tripod.com/code/generate_inserts.txt

Steve Kass
Drew University
http://www.stevekass.com

No comments:

Post a Comment