Saturday, February 16, 2013

REPLACE SQL SERVER STRING FUNCTION

Replace Sql server String function

            Replace string function replaces searches replaces strings and returns

              Syntax:

                             Replace(input,searchStr,replacestr)  

Ex:  Replace character  a with e

select replace( 'hallo','a','e') 

O/P: hello 

Ex2:  Replace all 'ab' with 'cd'

select replace('abcdabcd','ab','cd')  

O/P:
cdcdcdcd

Ex3:  String column in a table has wrong text, you can update with replace as follows

create table topics
(
  descd varchar(250)
)

insert into topics values(' hello this is nwyork')

//here part of the string has nwyork , but it suppose to be newyork

update topics set descd=replace(descd,'nwyork','newyork')

select descd from topics 
O/P:
descd
 hello this is newyork

Tags:REPLACE SQL SERVER STRING FUNCTION,Replace String function in SQl_Server 2012,How to replace strings in sql server,How to update text column with replace.

No comments:

Post a Comment