t1表中有一字段 a
a(列名)
123/234234
123/afsdf
123/oi23#
123/89324
123/@#$
123/2323
想在表内容改成
a(列名)
1234/234234
1234/afsdf
1234/oi23#
1234/89324
1234/@#$
1234/2323就是"/"前面的123改成1234 "/"后面的数据不变求此sql语句
a(列名)
123/234234
123/afsdf
123/oi23#
123/89324
123/@#$
123/2323
想在表内容改成
a(列名)
1234/234234
1234/afsdf
1234/oi23#
1234/89324
1234/@#$
1234/2323就是"/"前面的123改成1234 "/"后面的数据不变求此sql语句
这是SQL里面字符串截取,去baidu找下先关函数`!
replace(a,'123','1234')
这个不行啊
我是这么写的 但是不知道哪里有错误 执行后结果全是null
declare @t table(s varchar(50))
insert into @t select '123/234234'
union all select '123/afsdf'
union all select '123/oi23#'
union all select '123/89324'
union all select '123/@#$'
union all select '123/2323'update @t set s=replace(s,'123','1234')
select * from @t
1234/234234
1234/afsdf
1234/oi23#
1234/89324
1234/@#$
1234/2323
要是这么写...得写到下个世纪
declare @t table(s varchar(50))
insert into @t select '123/234234'
union all select '123/afsdf'
union all select '123/oi23#'
union all select '123/89324'
union all select '123/@#$'
union all select '123/2323'update @t set s=replace(s,'123','1234')
select * from @t
set a = Replace(a,'123','1234')
不久可以了吗
int intPos = strHref.IndexOf("/");
string strRight = strHref.Substring(intPos + 1);
a="1234/"+strRight;
SET [bbb] = stuff([bbb],1,3,'1234')
or
update tb_1 set tb_name=replace(tb_name,'123','1234')
insert into @t(s) select '123/234234'
union all select '123/afsdf'
union all select '123/oi23#'
union all select '123/89324'
union all select '123/@#$'
union all select '123/2323'
declare @aString varchar(100),@i int,@id int,@str varchar(100)
declare cus cursor for
select * from @t
open cus
fetch next from cus into @id,@aString
while @@fetch_status=0
begin
set @aString=rtrim(ltrim(@aString))
set @i=charindex('/',@aString)
if(@i>0)
begin
set @str=left(@aString,@i-1)
update @t set s=replace(@str,'123','1234')+right(@aString,len(@aString)-@i+1) where [id]=@id
end
fetch next from cus into @id,@aString
end
deallocate cusselect * from @t
update tb_1 set tb_name=stuff(tb_name,1,3,'1234')非常感谢大家的答复 因为...问题不是很难..所以分没给的太高...下次遇到难的问题...给高分..呵呵 分给的太低..有点惭愧...
觉得这样方便,而且万一/后也有123,就不会把后面的也替换了。