Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Using Replace in an Update command
Message
From
08/07/2005 18:16:01
Cetin Basoz
Engineerica Inc.
Izmir, Turkey
 
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 1.1
Database:
MS SQL Server
Miscellaneous
Thread ID:
01030778
Message ID:
01030803
Views:
13
>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
Previous
Reply
Map
View

Click here to load this message in the networking platform