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

Asked

Viewed 86 times

1

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

Except that there is a syntax error on line 12 where the first case is, someone knows 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);

1 answer

0

The CASE WHEN does not allow you to define a SET whole as you tried to do. You can only use it on the right hand side of the assignment, so:

...
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 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.