SQL Server Forums
Profile | Register | 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
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

rama108
Posting Yak Master

109 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

109 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
52325 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

109 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  
 New 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.08 seconds. Powered By: Snitz Forums 2000