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
 SQL Server 2012 Forums
 Other SQL Server 2012 Topics
 How to export result query to .txt or .csv
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

1 Posts

Posted - 05/22/2014 :  14:39:44  Show Profile  Reply with Quote
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

Almighty SQL Goddess

38200 Posts

Posted - 05/22/2014 :  14:58:13  Show Profile  Visit tkizer's Homepage  Reply with Quote
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
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000