Results 1 to 9 of 9

Thread: Update a word in entire table [RESOLVED]

  1. #1

    Thread Starter
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 2002
    Location
    Karachi
    Posts
    1,308

    Update a word in entire table [RESOLVED]

    Hello everybody,

    Someone generated SQL script for data migration and misspelled the word "Install" with "Instal". This is only in one field of a table but the table contains massive records.

    Is there some way to write a script to update Title field in such a way if it contains the word Instal, it should be replaced with Install. I have seen Instal is at the end of the other data.

    For example:
    abc
    abc2
    xyz Instal
    xyz2Instal

    This field should be:
    abc
    abc2
    xyz Install
    xyz2Install

    Thanks.
    Last edited by usamaalam; Dec 22nd, 2005 at 09:17 AM.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Update a word in entire table [URGENT]

    Code:
    UPDATE abc SET field = 'xyz Install' WHERE field = 'xyz Instal'

  3. #3
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: Update a word in entire table [URGENT]

    Or this will work too:

    UPDATE tblSample SET Field = REPLACE (Field, 'Instal', 'Install')

    Mind you, it applies a wild card on both sides of 'Instal', so correct spelling in that field will have 3 L's.
    Last edited by sevenhalo; Dec 22nd, 2005 at 09:18 AM.

  4. #4

    Thread Starter
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 2002
    Location
    Karachi
    Posts
    1,308

    Re: Update a word in entire table [URGENT]

    Thanks.

    sevenhalo's code is useful for me because data contains different words before Instal like "Store 1302 Instal" or "Store 6957 Instal" etc.

  5. #5
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Update a word in entire table [RESOLVED]

    What about the fields where Install (with two Ls) was originally there?

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Update a word in entire table [RESOLVED]

    Quote Originally Posted by mendhak
    What about the fields where Install (with two Ls) was originally there?
    They would be skipped.

  7. #7
    Banned
    Join Date
    Nov 2005
    Posts
    2,367

    Re: Update a word in entire table [RESOLVED]

    Hack - I think he was reffering to my example. It will over-correct if it's not a universal problem.

    Mend - I threw in a disclaimer so they knew ahead of time. I guess you could get really dirty and throw in another statement afterwards:

    UPDATE tblSample SET Field = REPLACE (Field, 'Installl', 'Install')

    Or, if you want to be clean and proper, you could make a sproc that will work (and maybe even abstract it enough so that it can be used on future issues).

    Me... I preffer to be dirty.

  8. #8
    I'm about to be a PowerPoster! mendhak's Avatar
    Join Date
    Feb 2002
    Location
    Ulaan Baator GooGoo: Frog
    Posts
    38,170

    Re: Update a word in entire table [RESOLVED]

    I like that.

  9. #9

    Thread Starter
    Frenzied Member usamaalam's Avatar
    Join Date
    Nov 2002
    Location
    Karachi
    Posts
    1,308

    Re: Update a word in entire table [RESOLVED]

    I did the same thing. Ran second script to replace any Installl with Install.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width