Re: replacing substring within string



(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
.



Relevant Pages

  • Re: Validations in bcp format file
    ... But SQL 2005 has a new rowset provider BULK, ... SELECT CASE field WHEN 'ABC' THEN 'DEF' ... Please check Books Online for exact syntax. ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ...
    (microsoft.public.sqlserver.tools)
  • Re: how to create csv file in DTA
    ... sum) as ABC ... Go to the transformations tab and make sure the SourceColumns appear as you ... Allan Mitchell MCSE,MCDBA, (Microsoft SQL Server MVP) www.SQLDTS.com - The site for all your DTS needs. ... I support PASS - the definitive, global community for SQL Server professionals - http://www.sqlpass.org "Kanan" wrote in message ...
    (microsoft.public.sqlserver.dts)
  • Re: Binary_Checksum - How secure is it?
    ... in an encrypted format and a different column has the original value in ... For example, if 'abc' is a password, its first encrypted and put in ... Erland Sommarskog, SQL Server MVP, esquel@xxxxxxxxxxxxx ... Books Online for SQL Server 2005 at ...
    (microsoft.public.sqlserver.security)
  • Windows Authentication from a workgroup to a domain sql server
    ... But the workgroup name is the same as ... SQL Part of abc domain ... Local user account name: test ... When the user tries to connect the SQL server comes back with: ...
    (microsoft.public.sqlserver.security)
  • Re: How to deploy a package to client PC ?
    ... Allan Mitchell ... "ABC" wrote in message ... on another PC from SQL Server, ... When I deploy a package to client, ...
    (microsoft.public.sqlserver.dts)