0

My source CSV is comma delimited.

Example

Col1, Col2, Col3

Destinatin SQL Table

Col1, Col2, Col3, Col4, Col5 ( Col4 and Col5 are like audit columns)

So when i do bcp import can these Col4 and Col5 set to some default values or should I have to massage the data / source file to include these before i execute bcp cmd.

Which is preferred way.

Use SSIS to read source / derive audit columns and map to destination.

or any other right way.

1 Answer 1

3

I think you have a couple of options:

  1. Change the schema of your destination table to include DEFAULT constraints on the two columns that will not get updated with values from your import file (and then remove them later if you don't need them

  2. Build an SSIS package -- it would probably take about the same amount of time as it would take you searching the Interweb for a solution using bcp

  3. Try using BULK INSERT through sqlcmd.exe or SQL Server Management Studio and adding in default values (SELECT c1, c2, c3, 'My default', GETDATE() FROM OPENROWSET('MSDASQL', 'Driver={Microsoft Text Driver (*.txt; *.csv)}; DefaultDir=C:\Path\To\Folder\With\CSV;','SELECT * FROM MyCsv.csv'))

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.