0

LOAD DATA INFILE should fill up only empty values with a specific content.

CSV:

Value1, Value2
-------------- 
1       123345 
2        
3       678901

EXPECTED RESULT:

Value1, Value2
--------------
1       123345
2       k0000123345
3       678901 

LOAD DATA INFILE .... SET .... ean = IFNULL(@d3, CONCAT('k0000',an))

...will result in still empty database values.

tshepang
  • 12,111
  • 21
  • 91
  • 136
Thomas B
  • 65
  • 7
  • Please - post some sample data and illustrate what is failing here. Almost anything might be wrong, or right, with this. –  Apr 22 '14 at 09:02
  • The mysql statement works but ean is empty when doing this instead of containing "k00001234" if csv has empty value. – Thomas B Apr 22 '14 at 09:04

1 Answers1

2

When you're using LOAD DATA INFILE an empty field in the input file is treated as an empty string (for string types) An empty string is not the same as null.

So for your input, your empty fields will fail the IFNULL() test. Check the length of the incoming data in your field and concatenate if it's zero:

LOAD DATA INFILE .... SET .... ean = IF(CHAR_LENGTH(@d3)>0,@d3,  CONCAT('k0000',an))