如表A:色号
1yi2-33e-9823i-888p
uu-45it-77888
99-ty99-ii333
通过SQL语句把表A字段色号第一个'-'前面的字符删掉。得到如下:33e-9823i-888p
45it-77888
ty99-ii333
1yi2-33e-9823i-888p
uu-45it-77888
99-ty99-ii333
通过SQL语句把表A字段色号第一个'-'前面的字符删掉。得到如下:33e-9823i-888p
45it-77888
ty99-ii333
调试欢乐多
from a
go
create table [tb]([col] varchar(30))
insert [tb] select '1yi2-33e-9823i-888p'
union all select 'uu-45it-77888'
union all select '99-ty99-ii333'update tb
set col=stuff(col,1,charindex('-',col),'')select * from tb
/*
col
------------------------------
33e-9823i-888p
45it-77888
ty99-ii333(3 行受影响)
*/
from a
Select substring(色號,charindex('-',色號)+1, len(色號)-(charindex('-',色號)+1))
go
create table [tb]([col] varchar(30))
insert [tb] select '1yi2-33e-9823i-888p'
union all select 'uu-45it-77888'
union all select '99-ty99-ii333'update tb
set col=right(col,len(col)-charindex('-',col))select * from tb
/*
col
------------------------------
33e-9823i-888p
45it-77888
ty99-ii333(3 行受影响)
*/再一种方法
insert [tb] select '1yi2-33e-9823i-888p'
union all select 'uu-45it-77888'
union all select '99-ty99-ii333'
select *,stuff(col,1,charindex('-',col,1),'') as col2 from tb/*
col col2
------------------- ----------------
1yi2-33e-9823i-888p 33e-9823i-888p
uu-45it-77888 45it-77888
99-ty99-ii333 ty99-ii333
*/drop table tb