Writing from SQL Server table to file using BCP

command-line sqlbulkcopy sql-server

Question

I just realized my caps was on from working in SQL Server, ha.

Anyways, Im trying to write from

serverName.databaseName.databaseInstanceName.TableName

to

C:\FileName.xml

using bcp and I want to write only columns Col1 and Col2, could I get a little syntax help? I'm struggling over here.

Thanks,

Ted

Accepted Answer

FYI for anyone else....

bcp "Select whatever from dbInstanceName.dbo.tableName" quesryout C:\output.txt -e C:\errors.txt -c -T -S localhost\dbName


Popular Answer

In order to create an XML version of the format file the command is identical except we use the -x parameter.

bcp "SELECT col1, col2 FROM AdventureWorks.HumanResources.Department" format nul -c -x -f department.xml -T -S servername


Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Is this KB legal? Yes, learn why