Import empty string(column default value) instead of NULL value when using bcp utility with a external data file and format file

StackOverflow https://stackoverflow.com/questions/12831347

  •  06-07-2021
  •  | 
  •  

Question

I have a small issue with using bcp import tool. This is the case I have a .csv data file (field separator if | character) and format file. I can import data into the table successfully, but it is importing NULL value instead of empty strings in data file. consider below as sample record in data file

col1|col2|||col5|col6

I got output like below

col1 col2 NULL NULL col5 col6

but I am expecting below output

col1 col2  (empty string) (empty string) col5 col6 

in my table definition, default values are empty string, is this due to an issue with data file (bcp data exporting command) or my data importing bcp command.

this is the command I used to import data bcp [database].[table] in M:\data\xx.csv -f M:\format\XX.FMT -S serverName -T

Thanks and All reply are welcome.

Was it helpful?

Solution

I believe you have to create the column of the table to have default value empty string ""

For example:

create table mytable (
  col1 varchar(10) default ""
)

OTHER TIPS

You can update from the interface in management studio In the editor properties of the column Default Value or Binding : (' ')

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top