Find and Replace a String in a Table

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)ASdeclare @sqlstring varchar(8000)Select  @sqlstring  = "Update " +  @Tablename + " Set " +  @FieldName + "= Replace(" + @FieldName + ",'" +  @FindString + "','" + @RepalceString  +"')"execute (@sqlstring)GOEXEC sp_st_FindANDReplaceString ('Orders','ShipName','QUICK','SLOW')

This replaces QUICK to SLOW in the field ShipName of the Orders table.


About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist