|
-
Dec 15th, 2010, 08:17 AM
#1
[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'
-
Dec 15th, 2010, 08:23 AM
#2
Re: Replacing Text In SQL Server 2000 Field
Try this:
Code:
select replace(field1, 'November2010', 'December2010') from tablename
-
Dec 15th, 2010, 08:35 AM
#3
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?
-
Dec 15th, 2010, 09:08 AM
#4
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
-
Dec 15th, 2010, 09:31 AM
#5
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|