January 24, 2012 at 12:59 pm
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
January 24, 2012 at 1:14 pm
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.
January 24, 2012 at 1:20 pm
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
January 24, 2012 at 1:45 pm
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
Viewing 4 posts - 1 through 3 (of 3 total)
You must be logged in to reply to this topic. Login to reply