Domanda

I'm writing scripts to export some tables to flat files every day. I'm looking at the BCP utility, but I'm not sure it has the kind of features I really need.

  1. For example, I need to output the fields out of order. That is, the 15th field in the MSSQL database should be the 2nd field in the flat file, et.c

  2. More importantly, some of the fields need to be altered. For example, if a certain field is null or contains some special values, I need to replace them with codes.

Is BCP the right tool for this? My gut tells me to do this in Perl instead.

È stato utile?

Soluzione

You can write a stored procedure and do all data transformations there. Then feed this stored procedure to bcp.

It will surely be faster than Perl.

SSIS is fast too; could be an option in case transformations are very complex.

Altri suggerimenti

You can use a query to order and format the columns directly with BCP

bcp Utility

"query"
Is a Transact-SQL query that returns a result set.

example:

bcp "SELECT Name FROM AdventureWorks.Sales.Currency" queryout Currency.Name.dat -T -c
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top