Login | Register   
LinkedIn
Google+
Twitter
RSS Feed
Download our iPhone app
TODAY'S HEADLINES  |   ARTICLE ARCHIVE  |   FORUMS  |   TIP BANK
Browse DevX
Sign up for e-mail newsletters from DevX


Tip of the Day
Language: SQL
Expertise: Beginner
Nov 24, 2003

Find and Replace a String in a Table

The folowing stored procedure will find and replace a string in a table:

CREATE PROCEDURE [dbo].[sp_st_FindANDReplaceString]
@Tablename  varchar(20),
@FieldName  varchar(20),
@FindString  varchar(30),
@RepalceString  varchar(30)
AS

declare @sqlstring varchar(8000)

Select  @sqlstring  = "Update " +  @Tablename + " Set " +  @FieldName + "
= Replace(" + @FieldName + ",'" +  @FindString + "','" + @RepalceString  +
"')"

execute (@sqlstring)
GO

EXEC sp_st_FindANDReplaceString ('Orders','ShipName','QUICK','SLOW')
This replaces QUICK to SLOW in the field ShipName of the Orders table.
Dinesh Asanka
 
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

Sitemap
Thanks for your registration, follow us on our social networks to keep up-to-date