Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Replace characters in the middle of a field. 1

Status
Not open for further replies.

Dimonet

IS-IT--Management
Oct 17, 2001
65
US
I have a field that contains information within it that I would like to replace. The following is an example.

111111|\\XXXXXX\XXXXXX\11111

I woould like to replace \\XXXXXX\XXXXXX\ with a new value. I need some help as to how to replace text that is wrapped by other text.

Any help would be appreciated.

Thanks,
Dimo
 
Use the Replace function:

Code:
Replace("abcdefffggghijkl", "fffggg", "fg")

The above example will return the following:

"abcdefghijkl"

post back with questions.

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
Thanks so much for your respone!

I am sorry I forgot to mention one other thing. And I also have a question about you response. The characters before and after the string that I want to replace will not always be the same. They will vary. So I need to know the syntax that will account for that variance. Also could you post what the complete code would look like if the table name were "test" and the field name was "test field".

Thanks again!

Dimo
 
Let's create a SQl query that displays the field before and after the replacement function:

Code:
Select A.[test field], Replace(A.[test field], "[blue]search string[/blue]", "[green]replacement string[/green]") as [Modified_test_field] 
FROM [red]test[/red] as A;

Update the blue and green code with search string and the replacement strings.

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
Ok that worked great but how do I get the new value back into the original field labeled "test field" in your example?

Thanks again,
Dimo
 
You must use an update query to accomplish this:

Code:
Update [test] as A Set A.[test field] = Replace(A.[test field], "search string", "replacement string");

This should update the field [test] with the modified value after the Replace function has rebuilt the string.

[COLOR=006633]Bob Scriver[/color]
MIState1.gif
[COLOR=white 006633]MSU Spartan[/color]
 
Thanks so much that worked great!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top