Tuesday, August 26, 2008

Using REPLACE in an UPDATE statement

hi all ,

Many times we need to update the records in our SQL tables in a way like
1. Removing unwanted spaces
2. Replacing some required text pattern from our existing records.

the easiest way to do that is by using REPLACE in an UPDATE statement :

for example :

if a record is " its a simple script" and we need to update it as " its a really simple script"

all we need to do is


update table_name set column = Replace(column ,'simple', 'really simple')


and that's it ... now where ever in the column in question holds 'Simple' in any record is now updated to 'really simple'

enjoy :-)