我的数据库中有一个名为Customers的表,其中包含:
+------------+---------------+-------------------------------------------+
|Customer ID | Customer_Name | Customer_Address |
| 00001 | JohnD | @ADDR;Number=21;Road=WalterRoad;@ENDADDR; |
+------------+---------------+-------------------------------------------+
属性Customer_ID(integer)
,Customer_Name(nvachar)
和Customer_Address(ntext)
的数据类型。
我想更改Customer_Address中的文本。我想只改变从沃尔特路到斯宾塞广场的道路,我想保留所有其他信息。
有没有这样做?
答案 0 :(得分:1)
使用REPLACE
:
<强> SqlFiddleDemo 强>
UPDATE Customers
SET Customer_Address = REPLACE(CAST(Customer_Address AS NVARCHAR(MAX)),'Road=WalterRoad','Road=Spencers Place')
WHERE Customer_ID = 1
-- AND INSTR(Customer_Address, 'Road=WalterRoad') > 0;
-- AND CHARINDEX(CAST(Customer_Address AS NVARCHAR(MAX)), 'Road=WalterRoad') > 0; -- I am not sure which RDBMS you use
您可以选择添加INSTR
以检查是否需要更新。