Results 1 to 9 of 9
  1. #1
    Join Date
    Apr 2004
    Location
    Holland
    Posts
    18

    Unanswered: Replace Query? Possible?

    Is it possible to make a replace query in SQL?

    So Find What, Replace With

    I have a table with email addresses. But now for more than 500 people it must be changed from user@company.nl to user@COMPANY2.nl

    Is this possible?

    Thanks in advance!

  2. #2
    Join Date
    Feb 2004
    Posts
    492
    Sure: Check out REPLACE in BOL.

  3. #3
    Join Date
    Apr 2004
    Location
    Holland
    Posts
    18
    I can't find it. Thanks anyway. But is it also possible with a query?

    Can somebody give me and example? ThX!!

  4. #4
    Join Date
    Feb 2004
    Posts
    492
    From BOL:


    REPLACE
    Replaces all occurrences of the second given string expression in the first string expression with a third expression.

    Syntax
    REPLACE ( 'string_expression1' , 'string_expression2' , 'string_expression3' )

    Arguments
    'string_expression1'

    Is the string expression to be searched. string_expression1 can be of character or binary data.

    'string_expression2'

    Is the string expression to try to find. string_expression2 can be of character or binary data.

    'string_expression3'

    Is the replacement string expression string_expression3 can be of character or binary data.

    Return Types
    Returns character data if string_expression (1, 2, or 3) is one of the supported character data types. Returns binary data if string_expression (1, 2, or 3) is one of the supported binary data types.

    Examples
    This example replaces the string cde in abcdefghi with xxx.

    SELECT REPLACE('abcdefghicde','cde','xxx')
    GO

    Here is the result set:

    ------------
    abxxxfghixxx
    (1 row(s) affected)

  5. #5
    Join Date
    Apr 2004
    Location
    Holland
    Posts
    18
    ThX mate. I will try to make a good one now.

  6. #6
    Join Date
    Apr 2004
    Location
    Holland
    Posts
    18
    I got it, ThX!

    For example:

    SELECT REPLACE(email_address, 'Pedro.nl', 'Pedro.com') from crm5.email
    Last edited by Pedr0; 09-29-04 at 08:30.

  7. #7
    Join Date
    Apr 2004
    Location
    Holland
    Posts
    18
    Hmmm, I was to early. It doens't change anything in the colum.

  8. #8
    Join Date
    Apr 2004
    Location
    Holland
    Posts
    18
    Now i got it.

    This is the query i want:

    Update crm5.email
    SET email_address =REPLACE(email_address, 'Company.nl', 'Pedro.com')
    from crm5.email

  9. #9
    Join Date
    Jul 2003
    Location
    The Dark Planet
    Posts
    1,401
    You will have to write a update query

    some thing like
    update crm5.email
    set email_address = REPLACE(email_address, 'Pedro.nl', 'Pedro.com')
    Get yourself a copy of the The Holy Book

    order has no physical Brett in The meaning of a Kaiser . -database data

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •