Saturday, June 2, 2012

Export to Text File directly from SQL Query

Export to Text File directly from SQL Query

EXEC xp_cmdshell 'bcp "SELECT * FROM Customer" queryout "C:\bcpcopy.txt" -T -c -t,'

Where -T says Trusted connection. Instead of thus we can use -U & -P for specific account
the character after t indicates the field delimiter. Here it is ,(comma)

For more options on BCP here: http://msdn.microsoft.com/en-us/library/ms162802.aspx

No comments: