如何从SQL Server中的字符串中删除第一个字符 [英] How to Remove first character from string in sql server
本文介绍了如何从SQL Server中的字符串中删除第一个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想删除 He 用其他字符替换.假设ABC
他对其他学生有积极影响
我在SQL Server中使用替换功能.
替换(他对其他学生有积极影响,他","ABC")
我遇到一个问题
参见输出
ABC对oABCr学生有积极影响
但我想替换第一个字符
请帮忙..
from below string i want to remove He replace with other character .suppose ABC
He is a positive influence on other students
I am using replace function in sql server.
replace(He is a positive influence on other students, ''He'',''ABC'')
I got one problem
see Output
ABC is a positive influence on oABCr students
but i want to make first character to replace
please help..
thanks in advance.
推荐答案
SQL还具有 SUBSTRING [ ^ ]这样:
SQL also has SUBSTRING[^] so:
SELECT 'ABC' + SUBSTRING(myColumn, 3, LEN(MyColumn)) FROM MyTable
将删除前两个字符并在ABC上添加大头钉
[edit]缺少右括号[/edit]
Will remove the first two characters and tack on ABC
[edit]Missed a close bracket[/edit]
尝试以下脚本
Try the below script
declare @str varchar(1000),
@word varchar(100),
@newword varchar(100)
select @str = 'He is a positive influence on other students',
@word = 'He',
@newword = 'ABC'
select @str Old, stuff(@str, charindex(@word, @str), len(@word), @newword) new
这篇关于如何从SQL Server中的字符串中删除第一个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文