if object_id('tb') is not null drop table tb go create table tb(bb varchar(8000)) insert into tb select 'abd<asfasdf' update tb set bb=left(bb,patindex('%<%',bb)-1) select * from tbabd
if object_id('tb') is not null drop table tb go create table tb(bb varchar(8000)) insert into tb select 'abd<asfasdf' insert into tb select '' insert into tb select null update tb set bb=case when patindex('%<%',bb)>0 then left(bb,patindex('%<%',bb)-1) else bb end select * from tbabdNULL考虑了''和null的替换
update a set ziduan=left(ziduan,charindex('<',ziduan)-1) where ziduan like '%<%'
drop table tb
go
create table tb(bb varchar(8000))
insert into tb select 'abd<asfasdf'
update tb set bb=left(bb,patindex('%<%',bb)-1)
select * from tbabd
drop table tb
go
create table tb(bb varchar(8000))
insert into tb select 'abd<asfasdf'
insert into tb select ''
insert into tb select null
update tb set bb=case when patindex('%<%',bb)>0 then left(bb,patindex('%<%',bb)-1) else bb end
select * from tbabdNULL考虑了''和null的替换