From: Erland Sommarskog on 8 Jul 2010 17:28 Roy Goldhammer (royg(a)yahoo.com) writes: > when u run replace(Field, 'abc', 'def') > > it replace any text in field who have 'abc' no metter what is before and > after the text > > But if i want to replace 'abc[', 'abc', 'abc def', 'abc > def', 'abc.def' ext.... > > and not replace 'abcd', 'abc_def' is there a way to do this? In addition to the other posts: the more advanced this get, the more apparent are the shortcomings of the T-SQL. This is where the possibility to write user-defined functions in the CLR is a very interesting alternative. -- Erland Sommarskog, SQL Server MVP, esquel(a)sommarskog.se Links for SQL Server Books Online: SQL 2008: http://msdn.microsoft.com/en-us/sqlserver/cc514207.aspx SQL 2005: http://msdn.microsoft.com/en-us/sqlserver/bb895970.aspx SQL 2000: http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
From: nj on 8 Jul 2010 18:21
Just another way to do the same thing. declare @a table (a varchar(20)) insert into @a values( 'abc[') insert into @a values( 'abc') insert into @a values( 'abc def') insert into @a values( 'abcdef') insert into @a values( 'abc.def') insert into @a values( 'abcd') insert into @a values( 'abc_def') update @a set a = REPLACE(a, 'abc', 'def') where checksum(a) not in(checksum('abcd'),checksum('abc_def')) select * from @a NJ |