How to update the last name of a person who starts with the initial 'Fabio%'?

Asked

Viewed 88 times

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 starts with 'Fábio%' to have the last name '%Borges' as I do this query?

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

This clasp updates the person’s name in the wrong way, as it includes the character '%' Oops, I didn’t explain that the 'Mello' would have to disappear.

  • You quoted several different banks, want the answer at all?

  • No, I quoted several banks to see if the answer would come faster. It’s wrong?

  • Absolutely! Try to focus only on the bank you’re using, it’s easier to get an accurate answer to your problem.

  • 1

    Why did they give me a -1? What did I do wrong?

  • It would be interesting to explain the same -1, the question is direct when facing the problem.

2 answers

3


It follows an alternative that only changes the "Mello":

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

Note that I’m just demonstrating the REPLACE. I stop the case of the question (which seems to me not well formulated, by the way), it makes no sense to complicate so much, nor use LIKE (Actually, I haven’t tested the LIKE in T-SQL).

The ideal in these cases is to put the values literally (by the full name, and no % ) in the WHERE and in the REPLACE.

  • 1

    Yours is the most appropriate one, now that I’ve seen that my answer adds but does not replace the one she wants. Anyway it was worth learning , I did not know the replace, I was already thinking about regex here :)

  • Boy... I tested here with another example type: Fábio Souza Mello and the right would turn Fábio Souza Borges but he excludes Fábio and Souza and is only 'Borges'...

  • I guess there’s no way to do that.

  • The easiest thing is to have the field surname and name. This fell into a selection test. So I came to consult.

  • @Alinegonzaga if you remove the Where clause, works perfectly, except that every name in your table that has "Mello", will be replaced to "Borges".

  • @Alinegonzaga It doesn’t make any sense that you said to delete Souza. Replace that I put only changes the Mello, and does not touch the rest.

  • 1

    @Bacco in fact, I tested it again the way Aline said, and it worked normal.http://i.imgur.com/ybIJlx0.png

  • 1

    @Diegof actually I only answered to show the replace. It makes no sense to use LIKE for the presented problem.

  • I’ll try it again.

  • WORKED! thanks it worked.

  • But mine worked using % in Fábio and like.

  • Gee, perfect use of replace, now I just need to memorize how to write it.

Show 7 more comments

2

You have to use:

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

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

Browser other questions tagged

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