我想更改'@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)));