22,209
社区成员
发帖
与我相关
我的任务
分享
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)
*/
select '/productFiles/'
+reverse(substring(reverse(pic),1,len(pic)-charindex('/',reverse(pic),1))) 'pic'
from wan
create table wan(pic varchar(100))
insert into wan
select '20054181241305.jpg' union all
select '/productFiles/2007-10/20071012154826320.gif'
select '/productFiles/'
+reverse(substring(reverse(pic),1,len(pic)-charindex('/',reverse(pic),1))) 'pic'
from wan
/*
pic
---------------------------------------
/productFiles/20054181241305.jpg
/productFiles/20071012154826320.gif
(2 row(s) affected)
*/
update ta set pic =case when CHARINDEX('/',PrdPic1,0)=0 then 'productFiles/'+PrdPic1 else 'productFiles/'+reverse(substring(reverse(PrdPic1),1,charindex('/',reverse(PrdPic1),1)-1))
这个有错误,运行不了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
update Cproduct set pic='/productFiles/'
+reverse(substring(reverse(pic),1,len(pic)-charindex('/',reverse(pic),1)))
我把这句拿到数据库里面执行了,报错
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
是不是把这段拿到查询分析器里面执行一下就可以了?