Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 export data to sql statement ?
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Posting Yak Master

143 Posts

Posted - 01/02/2007 :  11:15:39  Show Profile  Reply with Quote
I have table which include many records in it.
Table A (ID integer,Name nvarchar(30),Age text,Sex nvarchar(10))
1 ======A=========24=======Female
2 ======B=========35=======Male
3 ......
My problems : I want to export entire data above to sql file which
have following format :
Insert into TableB(ID,Name,Age,Sex) values(1,'A','24','Female')
Insert into TableB(ID,Name,Age,Sex) values(2,'B','35','Male')
Any one help me ?
Thank you very much.


United Kingdom
12543 Posts

Posted - 01/02/2007 :  11:20:53  Show Profile  Visit nr's Homepage  Reply with Quote
Do you want to copy the data to another table
Insert into TableB(ID,Name,Age,Sex) select ID, Name, Age, Sex from TableA

or to a file - in which case have a look at bcp

master..xp_cmdshell 'bcp mydb..TableA out c:\TableA.txt -SMyserver -T -c -t,'

Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page

Flowing Fount of Yak Knowledge

2886 Posts

Posted - 01/02/2007 :  11:28:44  Show Profile  Visit jezemine's Homepage  Reply with Quote
if the table has many records, I would recommend using bcp to export/import. it's much faster than generating and then executing 10m separate insert statements.

however if you really need the insert script, here are a few methods:
Go to Top of Page

Posting Yak Master

143 Posts

Posted - 01/02/2007 :  21:36:55  Show Profile  Reply with Quote
Thank all !

I perform command : sp_generate_inserts 'mytable'
How do i export result to file ?

Edited by - pamyral_279 on 01/02/2007 21:51:17
Go to Top of Page

Flowing Fount of Yak Knowledge

5581 Posts

Posted - 01/02/2007 :  22:50:22  Show Profile  Visit harsh_athalye's Homepage  Click to see harsh_athalye's MSN Messenger address  Send harsh_athalye a Yahoo! Message  Reply with Quote
Make use of OSQL command-line utility.

Harsh Athalye
Go to Top of Page

Patron Saint of Lost Yaks

30421 Posts

Posted - 01/02/2007 :  23:09:56  Show Profile  Visit SwePeso's Homepage  Reply with Quote
Copy the result in QA to a text file.

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

Starting Member

1 Posts

Posted - 03/23/2007 :  17:44:13  Show Profile  Reply with Quote
I want to insert specific rows.
I tried using
exec generate_inserts D_time,'','', from = (select * from D_time where time_id>20070000) but thats not working.
Has anybody any idea how to use the insert statements using where clause..
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2019 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000