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)
 Print sql statement to external file

Author  Topic 

rama108
Posting Yak Master

115 Posts

Posted - 2013-10-25 : 15:00:59
I have a sql statement in a variable and I want to print that variable to a text file. How to do that?

Thanks.

rama108
Posting Yak Master

115 Posts

Posted - 2013-10-25 : 15:26:27
I found the answer:

EXEC XP_CmdShell 'BCP "select * from table;" queryout
"C:\outputfilename.txt" -c -T '
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2013-10-25 : 22:58:38
see
http://visakhm.blogspot.in/2013/10/different-ways-to-export-sql-server.html

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
Go to Top of Page

rama108
Posting Yak Master

115 Posts

Posted - 2013-10-26 : 09:29:33
Thank you Vishakh.
Go to Top of Page
   

- Advertisement -