Monday, May 13, 2013

REPLACE Function in sql server

    REPLACE  replaces part of a text string, based on the number of characters you specify, with a different text string.

    Syntax :

    REPLACE(<old_text>,  <chars>, <new_text>)


    Parameters:



    <old_text>
       
    Any character string or binary expression that will be replace.

    <chars>
    Any character string or binary expression. This string is searching in
     <old_text>.

     <new_text>

    Any character string or binary expression. This string replace all occurrence of
    <chars>.



    Example :


    ------------------------CREATE Table------------------------
    create table #testtable
    (
     [Product Code] varchar(200)
    )
    -------------------insert data----------------------
    insert into #testtable
    select 'NewProduct1'

    --------------------Now use Replace function to replace 'N' char to 'OB'--------------------
    select REPLACE([Product Code],'N','OB') from #testtable 

    --------------------output-----------------------------
    OBewProduct1


    Drop table    #testtable






If you are searching life partner. your searching end with kpmarriage.com. now kpmarriage.com offer free matrimonial website which offer free message, free chat, free view contact information. so register here : kpmarriage.com- Free matrimonial website