Replace (--)

  • Hi,

    I need to do a replace of "--" per nothing.

    I have tried this:

    replace(string,'--','')

    Because the "--" it's a comment i can´t do this...

    How can i replace "--" per ''

    thank you

  • I've just tested this and it works.

    select replace('This -- is a sample --','--','')

    Returning: This is a sample

    Cheers

    Leo

    Leo
    Nothing in life is ever so complicated that with a little work it can't be made more complicated.

  • I just tried this on 2008 and the replace works as expected. The -- has been replaced with an empty string, the - is left asis. I don't have access to 2005 at the moment.

    with cte as

    (select '--' as col1

    union all

    select '-'

    )

    select REPLACE(col1,'--','') as repcol from cte

    ;

    Dave

  • i'm guess it's more complicated than the original post's simple REPLACE function

    ...for example if he's trying to replace stored procedure text, but there's code that does something like ISNULL(Category,'--');

    he cannot simply replace the -- because the comments after it break the proc.

    he'll need to do a smarter search, like searching for '--' instead of just --, or use regular expressions to get fancy.

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!

Viewing 4 posts - 1 through 3 (of 3 total)

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