Monday, March 26, 2012

replace T-SQL fonction

I would like to know how to use a replace fonction on a table
Like, currently, the syntax for replace is

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

but I would like to do something more like

SELECT REPLACE ((SELECT * FROM TABLE1) , 'cde', 'xxx')

Thanks to reply!I've found my problem ... which was in fact simple

it's:

select replace (FieldName , 'abc' , 'xxx') from MyTable...

the problem was that my FieldName was a Text field... which doesn't work... you need a varchar or nvarchar there...
so:

select replace (CAST(FieldName AS varchar(8000)), 'abc', 'xxx') from myTable

Thanks anyway!|||You should consider changing your fieldtype to VARCHAR if TEXT is not required. It will make coding easier and improve efficiency.

blindmansql

No comments:

Post a Comment