Please start any new threads on our new site at http://forums.sqlteam.com. 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
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Print sql statement to external file
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rama108
Posting Yak Master

115 Posts

Posted - 10/25/2013 :  15:00:59  Show Profile  Reply with Quote
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 - 10/25/2013 :  15:26:27  Show Profile  Reply with Quote
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

India
52326 Posts

Posted - 10/25/2013 :  22:58:38  Show Profile  Reply with Quote
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 - 10/26/2013 :  09:29:33  Show Profile  Reply with Quote
Thank you Vishakh.
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.03 seconds. Powered By: Snitz Forums 2000