How to export results in to a file in SQL server 2008

Recently I countered a situation where I need to insert a bulk amount of data from a table in one database to another alias table in other database.

For bulk insert I found out many solutions and this works for me correctly.

But before that I need to export the data to a file, for which below methods helped me.

SELECT * INTO OUTFILE "D:result.txt"
FIELDS TERMINATED BY ',' 
OPTIONALLY ENCLOSED BY '"'
LINES TERMINATED BY 'n'
FROM DBO.TESTTABLE;

or using SQLCMD mode

:OUT D:result.txt
SELECT * FROM DBO.TESTTABLE;

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.