Is there a way in SQL Server 2000 to extract data from a table, such that
the result is a text file in the format of "Insert Into..." statements, i.e.
if the table has 5 rows, the result would be 5 lines of :
insert into Table ([field1], [field2], .... VALUES a,b,c)
insert into Table ([field1], [field2], .... VALUES d, e, f)
insert into Table ([field1], [field2], .... VALUES g, h, i)
insert into Table ([field1], [field2], .... VALUES j, k, l)
insert into Table ([field1], [field2], .... VALUES m, n, o)
Thanks in advance 5 2905
INSERT INTO TABLE1(FIELD1,FIELD2)
SELECT ABC, XYZ from TABLE2 where bla bla
or
INSERT INTO TABLE1(A,B,C)
SELECT X,Y, 'some static text' FROM TABLE2
the number of columns must tally
Chad Richardson wrote: Is there a way in SQL Server 2000 to extract data from a table, such
that the result is a text file in the format of "Insert Into..."
statements, i.e. if the table has 5 rows, the result would be 5 lines of :
insert into Table ([field1], [field2], .... VALUES a,b,c) insert into Table ([field1], [field2], .... VALUES d, e, f) insert into Table ([field1], [field2], .... VALUES g, h, i) insert into Table ([field1], [field2], .... VALUES j, k, l) insert into Table ([field1], [field2], .... VALUES m, n, o)
Thanks in advance
You can by creating a calculated column that does the insert format:
select 'insert into table (id, name, phone) values (' +
cast(id as varchar(10)) + ',' +
quotename(name,'''') + ',' +
quotename(phone,'''') + ')'
from namelist
results:
insert into table (id, name, phone) values (1, 'James', 'Smith')
insert into table (id, name, phone) values (2, 'John', 'O''Kieth')
--
David Rowland
For a good User and Performance monitor, try DBMonitor http://dbmonitor.tripod.com
You can by creating a calculated column that does the insert format:
select 'insert into table (id, name, phone) values (' +
cast(id as varchar(10)) + ',' +
quotename(name,'''') + ',' +
quotename(phone,'''') + ')'
from namelist
results:
insert into table (id, name, phone) values (1, 'James', 'Smith')
insert into table (id, name, phone) values (2, 'John', 'O''Kieth')
--
David Rowland
For a good User and Performance monitor, try DBMonitor http://dbmonitor.tripod.com
Thanks all for the responses!
"Chad Richardson" <chad@NIXSPAM_chadrichardson.com> wrote in message
news:11*************@corp.supernews.com... Is there a way in SQL Server 2000 to extract data from a table, such that the result is a text file in the format of "Insert Into..." statements, i.e. if the table has 5 rows, the result would be 5 lines of :
insert into Table ([field1], [field2], .... VALUES a,b,c) insert into Table ([field1], [field2], .... VALUES d, e, f) insert into Table ([field1], [field2], .... VALUES g, h, i) insert into Table ([field1], [field2], .... VALUES j, k, l) insert into Table ([field1], [field2], .... VALUES m, n, o)
Thanks in advance This discussion thread is closed Replies have been disabled for this discussion. Similar topics
6 posts
views
Thread by Tuong Do |
last post: by
|
9 posts
views
Thread by Hi5 |
last post: by
|
1 post
views
Thread by Pratik Gupte |
last post: by
|
reply
views
Thread by Mamatha |
last post: by
|
2 posts
views
Thread by savigliano |
last post: by
| | | |
2 posts
views
Thread by Dhananjay |
last post: by
|
8 posts
views
Thread by Betikci Boris |
last post: by
| | | | | | | | | | |