Re: replacing substring within string
- From: Erland Sommarskog <esquel@xxxxxxxxxxxxx>
- Date: Mon, 5 Nov 2007 22:44:18 +0000 (UTC)
(mirandacascade@xxxxxxxxx) writes:
-- whenever @strValFromFrontEnd contains the substring 'abc',
transform it such that
-- it gets replaced by '123'; examples:
-- @strValFromFrontEnd @strTransformedVal
-- -------------------------------- ------------------------------
-- four score abc and four score 123 and
-- hello abc world abc yo hello 123 world 123 yo
SET @strTransformedVal = ??
Question: if the goal is to arrive at @strTransformedVal as described
above, what is the best way to accomplish that...should one use the
REPLACE function?
As long as the job is so simple that replace() does the job, why not
use it?
I would not be surprised, though, if you find that the affair is more
complex. Keep in mind that T-SQL is not the best tool for string
manipulation. If you are on SQL 2005, you have access to the CLR and
can use C# or VB.Net in SQL Server.
--
Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx
Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/prodtechnol/sql/2005/downloads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinfo/previousversions/books.mspx
.
- References:
- replacing substring within string
- From: mirandacascade
- replacing substring within string
- Prev by Date: Re: How to add a PK column to a View?
- Next by Date: Re: max number of instances?
- Previous by thread: replacing substring within string
- Next by thread: How to add a PK column to a View?
- Index(es):
Relevant Pages
|