Results 1 to 5 of 5

Thread: [RESOLVED] Replacing Text In SQL Server 2000 Field

  1. #1

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

    Resolved [RESOLVED] Replacing Text In SQL Server 2000 Field

    Lets say I have a field in an SQL Server 2000 table with 20 fields. In one field, called Field1, I have entries such as:

    November2010\Grocery\Apples
    November2010\Grocery\Oranges
    November2010\Grocery\Grapes
    November2010\Grocery\Bananas
    etc

    I want to replace November2010 in that field while leaving the existing text "\Grocery\Whatever" in place.

    I tried
    Code:
    select field1 replace('November2010','November2010','December2010') from tablename
    But it gives me a snytax error near 'November2010'

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Replacing Text In SQL Server 2000 Field

    Try this:
    Code:
    select replace(field1, 'November2010', 'December2010') from tablename

  3. #3

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

    Re: Replacing Text In SQL Server 2000 Field

    That ran without errors and listed out that specific field with December2010 as the first part of the entry rather than November2010.

    However, when I then did a SELECT * FROM tablename, the field still had November2010 in it.

    Do I need to do a Commit?

  4. #4
    A SQL Server fool GaryMazzone's Avatar
    Join Date
    Aug 2005
    Location
    Dover,NH
    Posts
    7,493

    Re: Replacing Text In SQL Server 2000 Field

    That is just a Select statement Hack. If you want to update the database field you need to Run Update
    right
    Sometimes the Programmer
    Sometimes the DBA

    Mazz1

  5. #5

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

    Re: Replacing Text In SQL Server 2000 Field

    Every example of the REPLACE function that I found used SELECT, so that is what I did.

    However, this worked splendidly
    Code:
    update tablename set field1 = replace(field1, 'November2010', 'December2010')
    Thanks.

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