Search for value and Replace

  • I have the table like this:

    CREATE TABLE #TEMP(GROUP_ID NCHAR(50),

    TEXT VARCHAR(MAX))

    INSERT INTO #TEMP

    SELECT '100','The purpose of this group 100 is to know the .....'

    UNION ALL

    SELECT '1000','The prupose of the group 1000 is to get ...'

    UNION ALL

    SELECT '1230', 'This is sample text 1230....'

    Result:

    Group_ID Text

    100 The purpose of this group 100 is to know the .....

    1000 The prupose of the group 1000 is to get ...

    1230 This is sample text 1230....

    Now i need to search for Group_ID in text column and replace with empty string.

    Result should like:

    100 The purpose of this group is to know the .....

    1000 The prupose of the group is to get ...

    1230 This is sample text ....

    I tried by using replace function but its not working to replace value from other column.

    select REPLACE(text,Group_ID,' ')

    from #temp

    Can anyone have idea about this..

  • From your table design, I would say is a problem with trailing spaces.

    Try this and tell us if it worked.

    select REPLACE(TEXT,RTRIM(Group_ID),' ')

    from #temp

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Why don't you take the group numbers out of the insert text?

  • Animal Magic (9/17/2012)


    Why don't you take the group numbers out of the insert text?

    Maybe because he can't control the past and have to correct the data.

    Prevention is key, but you can't change the past.

    Luis C.
    General Disclaimer:
    Are you seriously taking the advice and code from someone from the internet without testing it? Do you at least understand it? Or can it easily kill your server?

    How to post data/code on a forum to get the best help: Option 1 / Option 2
  • Fair enough 🙂 Am sure your suggestion will sort the issue anyway

Viewing 5 posts - 1 through 5 (of 5 total)

You must be logged in to reply to this topic. Login to reply