Home SQL PHP HTML Perl PowerBuilder C/C++ General Solutions Contacts

SQL

Index
Search and Replace
Multiple Outer Joins
Comparing Dates

Procedures

Template

Search and replace in database fields

The Problem

There is information in the database that needs replacing, but this information is a substring of 1 or more rows of a field in the table, we need an equivalent to a SQL search and replace.

Code

How to use

Replace the items in the code enclosed in square brackets [], with the following values :-

  • [tablename] - The name of the table in the database.
  • [fieldname] - The name of the field (column) within the table.
  • [find] - The text to be replaced (text to be searched for).
  • [replace] - The text which will replace the text found.

Suggestions

You may wish to use a programming language which supports Dynamic SQL to make a generic function. This could take the items in square brackets as parameters to produce a very powerful database search and replace tool.

Details

Author:     Wayne Jones
Created:    1 December 2002
Works with: MS-SQL, Sybase
This is Code, all contents copyright - © Wayne Jones 2004.