日期:2014-05-18 浏览次数:20439 次
create table wan(pic varchar(100)) insert into wan select '20054181241305.jpg' union all select '/productFiles/2007-10/20071012154826320.gif' update wan set pic='/productFiles/' +reverse(substring(reverse(pic),1,len(pic)-charindex('/',reverse(pic),1))) select * from wan /* pic --------------------------------------- /productFiles/20054181241305.jpg /productFiles/20071012154826320.gif (2 row(s) affected) */
------解决方案--------------------
create table ta(pic varchar(128)) insert ta select '20054181241305.jpg' union select '/productFiles/2007-10/20071012154826320.gif' select * from ta /* pic 20054181241305.jpg /productFiles/2007-10/20071012154826320.gif */ update ta set pic =case when CHARINDEX('/',pic,0)=0 then '/productFiles/'+pic else '/productFiles/'+reverse(substring(reverse(pic),1,charindex('/',reverse(pic),1)-1)) end /* pic /productFiles/20054181241305.jpg /productFiles/20071012154826320.gif */ drop table ta