Wednesday, February 24, 2010

Replace Some text in single column of same table:

UPDATE dbo.Tablename SET Column_name= REPLACE(column_name, 'Existing text', 'Replace text')
Example:
I have one table called L_Newsletter_Templates , with column name Newsletter_Imagepath I want to replace 'suresh' with 'localhost' then i will write my query as follows

UPDATE dbo.L_Newsletter_TemplatesSET Newsletter_Imagepath = REPLACE(Newsletter_Imagepath, 'suresh', 'localhost')

Replace is a sqlserver builtin function which can takes 3 arguments
1.Column name
2.what text we want to replace
3. with text

By using this we are simply update same thing in all columns.

No comments:

Post a Comment