How do I make a case when no load data infile?

1

I need to make a replace of the same column of several distinct string, make a load data infile .

It just gives a syntax error on line 12 where it has the first case, does anyone know what I'm doing wrong the code is below?

LOAD DATA LOCAL INFILE 'c:/temp/reportes/fornecedor.csv'
                            INTO TABLE reparo.pn_digitron
                            FIELDS TERMINATED BY ','
                            ENCLOSED BY '"'
                            LINES TERMINATED BY '\r\n'
                            IGNORE 1 LINES
                            (@modelo,@tipo,
                            @part_number,@fornecedor,@descricao_bom)
                            SET
                            'Modelo' = trim(@modelo),
                            'tipo' = trim(@tipo),
                            case when 'part_number' = 'DT' then
                            'part_number' = trim(replace(@part_number, 'DT', 'MB')),
                            when 'part_number' = 'NB' then 
                            'part_number' = trim(replace(@part_number, 'NB', 'MB')), 
                            when 'part_number' = 'EBG' then
                            'part_number' = trim(replace(@part_number, 'EBG', 'MB')),
                            when 'part_number' = 'SMALL' then
                            'part_number' = trim(replace(@part_number, 'SMALL', 'SB')) end,
                            'fornecedor' = trim(@fornecedor),
                            'descricao_bom' = trim(@descricao_bom);
    
asked by anonymous 12.07.2016 / 16:35

1 answer

0

CASE WHEN does not allow you to define an integer expression of SET as you tried to do. You can only use it on the right side of the assignment, like this:

...
SET
    'Modelo' = trim(@modelo),
    'tipo' = trim(@tipo),
    'part_number' = CASE 
                      WHEN 'part_number' = 'DT' THEN trim(replace(@part_number, 'DT', 'MB'))
                      WHEN 'part_number' = 'NB' THEN
                      ...
                      END 
    
12.07.2016 / 17:57