dbTalk Databases Forums  

Re: replacing substring within string

comp.databases.ms-sqlserver comp.databases.ms-sqlserver


Discuss Re: replacing substring within string in the comp.databases.ms-sqlserver forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
Erland Sommarskog
 
Posts: n/a

Default Re: replacing substring within string - 11-05-2007 , 04:44 PM






(mirandacascade (AT) yahoo (DOT) com) writes:
Quote:
-- 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 (AT) sommarskog (DOT) se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx


Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.3
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.