我想使用Management Studio运行查找和替换某些sql数据的查询.我基本上想删除任何内容中的免费字.
我试过运行这个查询;
UPDATE Table_1
SET ContentDetails = REPLACE(ContentDetails, 'FREE', '')
WHERE (ContentDetails LIKE '%FREE%')
Run Code Online (Sandbox Code Playgroud)
但我得到一个错误,说数据类型文本对替换函数的参数1无效.
由于你有一个text专栏,你需要使用updatetext,这是痛苦的,充其量.但是,你可以投contentdetails的varchar(max),你会是桃色的.
update table_1
set contentdetails = replace(cast(contentdetails as varchar(max)), 'FREE', '')
where contentdetails like '%FREE%'
Run Code Online (Sandbox Code Playgroud)
此外,我强烈建议您考虑将该列转换text为varchar(max).它,连同ntext和image,是当前过时的数据类型,这将在SQL Server中的未来的某一时刻被删除.