replace help

  • I need to replace a name in this example Brighton in the field " Description" which looks something like this (BASE, Brighton, BLB3639, Maple, Bright White, Maple Drawers w/Blum Motion, Right Hand, Deluxe Cabinet Construction) with the correct name from the below table. The default value should be changed to the replacement value.

    defaultvaluereplacement

    Colony Colonial

    Cottage Colonial II

    Brighton Belleair

    Homestead Shaker

    Homestead II Shaker II

    Harmony Hawthorne

    Savannah Springfield

    Briarwood Bronson

    Jamestown Jupiter

    Shelby Sanford

    Lawrence Longwood

    Yorktown Youngstown

  • This is not a very clear description of what you are trying to do. Can you post some DDL, consumable sample data and an example of the expected results?

    "I cant stress enough the importance of switching from a sequential files mindset to set-based thinking. After you make the switch, you can spend your time tuning and optimizing your queries instead of maintaining lengthy, poor-performing code."

    -- Itzik Ben-Gan 2001

  • Use Jeff Moden's splitter (see Alan's signature) to split the column, LEFT join your correction table and USE FOR XML to concatenate the result (using either the replacement text or the original)

    Far away is close at hand in the images of elsewhere.
    Anon.

  • this statement would work but I was hoping to use a table so I don't have to hardcode this in the software.

    replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(replace(m1_dc.dbo.SalesOrderLines.omlPartLongDescriptionText,'Brighton','Belleair'),'Colony','Colonial'),'Cottage','Colonial II'),'Homestead','Shaker'),'Homestead II','Shaker II'),'Harmony','Hawthorne'),'Savannah','Springfield'),'Briarwood','Bronson'),'Jamestown','Jupiter'),'Shelby','Sanford'),'Lawrence','Longwood'),'Yorktown','Youngstown')

  • Take a look at this thread.

    http://www.sqlservercentral.com/Forums/Topic1688498-3077-1.aspx

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply