Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • SQl : How to replace a string in SQL server column ?

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 455
    Comment on it

    We know that the data can be changed inside a field by using update command. In this article I will guide you to replace part of the data without changing the entire data of the field. For this we will use replace command to replace a part of the contents in a fields. We will use the following table (Employee) for illustration purpose:

    Name Department
    Amit .NET Tech
    Sumit Java Tech
    Anit PHP Tech

    Now we will use replace in query to change the department by using below query.

    UPDATE Employee SET Department=REPLACE(Department, 'Tech', 'Technology') 

    The output of the query will be as below :

    Name Department
    Amit .NET Technology
    Sumit Java Technology
    Anit PHP Technology

    We can also use the WHERE clause if we want to do replace for a selected records. For example if we want to do the replace operation for employee Amit , we will use the below query :

    UPDATE Employee SET Department=REPLACE(Department, 'Tech', 'Technology') WHERE Name='Amit'

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: