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 2005 Forums
 Transact-SQL (2005)
 Save a query Result

Author  Topic 

richieHunter
Starting Member

1 Post

Posted - 2009-12-21 : 18:34:58
Hello, i'd like to know how can i save the result of a query to a .txt or .sql file using transac sql, I've consult some sources but i thinks this is not a very popular question because I've not found good informatio about this.

thanks for yor time

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2009-12-21 : 18:59:03
I use bcp.exe. Here's an example: bcp.exe db1.dbo.t1 out c:\someFile.csv -c -t, -Sserver1\instance1 -T -r\r\n

And you can call it from T-SQL via xp_cmdshell.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog

"Let's begin with the premise that everything you've done up until this point is wrong."
Go to Top of Page
   

- Advertisement -