2

I have an articles table and I need to add the year to the name

Before

Bicicleta rodado 20", freestyle Mirraco Blend
Bicicleta rodado 20", freestyle Mirraco Blend (azul)
Bicicleta rodado 20", freestyle Mirraco Blend (negro)
Bicicleta rodado 20", freestyle Mirraco Blink
Bicicleta rodado 20", freestyle Mirraco Blink (blanco con azul)
Bicicleta rodado 20", freestyle Mirraco Blink (marron)
Bicicleta rodado 20", freestyle Mirraco N°7
Bicicleta rodado 20", freestyle Mirraco N°7 (negro con blanco)
Bicicleta rodado 20", freestyle Mirraco N°7 (purpura con blanco)

After

Bicicleta rodado 20", freestyle Mirraco Blend 2010
Bicicleta rodado 20", freestyle Mirraco Blend 2010 (azul)
Bicicleta rodado 20", freestyle Mirraco Blend 2010 (negro)
Bicicleta rodado 20", freestyle Mirraco Blink 2010
Bicicleta rodado 20", freestyle Mirraco Blink 2010 (blanco con azul)
Bicicleta rodado 20", freestyle Mirraco Blink 2010 (marron)
Bicicleta rodado 20", freestyle Mirraco N° 7 2010
Bicicleta rodado 20", freestyle Mirraco N° 7 2010 (negro con blanco)
Bicicleta rodado 20", freestyle Mirraco N° 7 2010 (purpura con blanco)

The rule would be to add the year before the parenthesis. And if there is no parenthesis, add it at the end. It can't be counting word because the count is not always the same (N° 7 in this particular case)

0

2 Answers 2

2

This should get what you want if you are looking to inject the date:

SELECT 
  CASE
    WHEN (INSTR( your_field,  '(' ) > 0)
      THEN REPLACE(your_field, '(', '2010 (')
    ELSE CONCAT (your_field, ' 2010')
  END 
FROM your_table;
Sign up to request clarification or add additional context in comments.

Comments

0

Try this:

SELECT
case instr(accountcode,'-') when instr(accountcode,'-') = 0 then 
concat(accountcode, '  2010') else 
concat(left(accountcode,instr(accountcode,'-')-1), concat(' 2010',right(accountcode,instr(accountcode,'-')-2))) 
end 
FROM account a;

1 Comment

Sorry it happens to me too, I didn't see the result with my data, let me check it out

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.