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

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 SQL query export to a file

Author  Topic 

sportsguy
Starting Member

39 Posts

Posted - 2013-03-28 : 10:36:24
How do i set the output file structure and destination in code?

Pipe delimited
e:\DATA\Extracts\filename.txt

I hate having to go in manually and set it up everytime,
as this is not the default. .

thanks in advance. . .

MS Access 20 years, SQL hack

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-28 : 10:47:39
use bcp with queryout option.

http://www.nigelrivett.net/SQLTsql/BCP_quoted_CSV_Format_file.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

sportsguy
Starting Member

39 Posts

Posted - 2013-03-28 : 11:51:21
visakh16,

sorry, you link describes importing text to a data table,
I am asking about exporting a query to text. . .

thanks for trying though. ..

sportsguy

MS Access 20 years, SQL hack
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-03-28 : 12:18:31
bcp has a query out option which you can utilise to export query results to text. that link was just to show usage of format file

see

http://sqlfool.com/2008/12/bcp-basics/

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -