How to update the surname of a person starting with the initial 'Fabio%'?

0

It is possible to do this, I have a name of a person who is 'Fábio Mello' and I want to update the name that begins with 'Fábio%' to have the surname '% Borges' how do I make this query?

update pessoa set nome = '%Borges' where nome = 'Fabio%' 

This class refreshes the person's name in the wrong way because it includes the character '%' Oops, I did not explain that 'Mello' would have to disappear.

    
asked by anonymous 06.03.2016 / 19:15

2 answers

3

Here is an alternative that only changes "Mello":

UPDATE pessoa SET nome = REPLACE(nome, 'Mello', 'Borges' ) WHERE nome LIKE 'Fabio' 

Note that I am only demonstrating REPLACE . I do not know how to do this, but I do not know how to do it. I'm not sure what to do with T-SQL.

The ideal in these cases is to literally put the values (by the full name, and nothing of%) in LIKE and LIKE .

    
06.03.2016 / 20:06
2

You have to use:

UPDATE pessoa SET nome = 'Fábio Borges' WHERE nome LIKE 'Fábio%';

nome = '%Borges' makes the name literally become "% Borges", because the % character only works to match anything in the where clause.

    
06.03.2016 / 19:40