Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Using Replace in an Update command
Message
De
08/07/2005 18:16:01
Cetin Basoz
Engineerica Inc.
Izmir, Turquie
 
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 1.1
Database:
MS SQL Server
Divers
Thread ID:
01030778
Message ID:
01030803
Vues:
14
>Hi,
>
>How would I replace a portion of a field in a table with another string for all records that match some criteria?
>
>Let's say I have a SKU field that is "1234-xxxx" and I want to change the field to be "abcd-xxxx":
>
>
>update Orders set SKU = SKU.Replace("1234","abcd") where ProductID = 285
>
>
>Am I on the right track? I was expecting intellisense to show in Visual Studio 2003, but it doesn't.
>
>Thanks in advance,
>Paul

replace() changes all occurences. Use stuff() instead. ie:

Replace chars 1-4 with "abcd":
update Orders set SKU = stuff(SKU,1,4,'abcd') where ProductID = 285
Replace syntax would be:
update Orders set SKU = replace(SKU,'1234','abcd') where ProductID = 285
PS: Up to including SQL server 2000 T-SQL doesn't support method chaining like C#
SKU.Replace(...) not supoported IOW.
Replace(SKU,...)
Cetin
Çetin Basöz

The way to Go
Flutter - For mobile, web and desktop.
World's most advanced open source relational database.
.Net for foxheads - Blog (main)
FoxSharp - Blog (mirror)
Welcome to FoxyClasses

LinqPad - C#,VB,F#,SQL,eSQL ... scratchpad
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform