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.

2
  • Please - post some sample data and illustrate what is failing here. Almost anything might be wrong, or right, with this.
    – user1864610
    Apr 22, 2014 at 9: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, 2014 at 9:04

1 Answer 1

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))
0

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.