create table tb(imgPath varchar(50)) insert into tb select 'd1/d2/f1'--d1/d2/dd/f1 select left(imgPath,len(imgPath)-charindex('/',reverse(imgPath))) from tb