devxlogo

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.

Charlie has over a decade of experience in website administration and technology management. As the site admin, he oversees all technical aspects of running a high-traffic online platform, ensuring optimal performance, security, and user experience.

See also  How Seasoned Architects Evaluate New Tech

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.