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
 Other SQL Server 2012 Topics
 How to export result query to .txt or .csv

Author  Topic 

afonso.rodrigues
Starting Member

1 Post

Posted - 2014-05-22 : 14:39:44
Hello,
I'm Afonso Rodrigues, Developer Java, user Database.
I'm looking for a procedure to export of result query in .txt or .csv.

I'm finding bcp and sqlcmd.
But it this a single possibility?

Afonso Rodrigues

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2014-05-22 : 14:58:13
I'd use bcp. Here's an example:

bcp.exe "select column5, column8 from database1.dbo.table1 t1 join database1.dbo.table2 t2 on t1.column1 = t2.column1" queryout c:\temp\bcpout.csv -c -t, -T -Sserver1\instance1 -r\r\n

Tara Kizer
SQL Server MVP since 2007
http://weblogs.sqlteam.com/tarad/
Go to Top of Page
   

- Advertisement -