我想更改'@sadim嗨,等等等等等'。 '嗨,等等等等'。在SQL Server中。正則表達式在SQL Server中使用替換
我使用這個查詢,但它不工作:
update mytable
set ttext = REPLACE(ttext, '@% ' , '');
我想更改'@sadim嗨,等等等等等'。 '嗨,等等等等'。在SQL Server中。正則表達式在SQL Server中使用替換
我使用這個查詢,但它不工作:
update mytable
set ttext = REPLACE(ttext, '@% ' , '');
update stack
set name = SUBSTRING(name,CHARINDEX(' ',name),LEN(name));
這將允許你跳過@username部分。作爲字符串開始與@username獲得子字符串之後 這裏棧是你的表,並將其命名爲您的列名
來到正則表達式的一部分,請看看這個
https://dba.stackexchange.com/questions/162816/sql-server-replace-with-wildcards
如果在所有@username在字符串中間存在使用:
update stack
set name =
case
when name like '@%' then SUBSTRING(name,CHARINDEX(' ',name),LEN(name))
when name like '%@%' then CONCAT(
SUBSTRING(name,0,CHARINDEX('@',name)-1),
SUBSTRING(SUBSTRING(name,CHARINDEX('@',name),LEN(name)),
CHARINDEX(' ',
SUBSTRING(name,CHARINDEX('@',name),LEN(name))),
LEN(
SUBSTRING(name,CHARINDEX('@',name),LEN(name))
)
)
)
end
使用下面的更新查詢
update mytable
set ttext = (select substring(ttext,charindex(' ',ttext)+1,len(ttext) - charindex(' ',ttext)));