表字段有img_url,lon,lat 三个字段,目的是当lon 和lat 获取img_url中 '经'和 '纬'的位置,想请前辈帮写个条件语句:img_url字符包含'经'执条件1,否则执行条件2,先感谢前辈了!
CREATE trigger TR_city_locate
on dbo.city_locate for insert,update
as
beginif (1=0) --想在这写个条件语句,如果a.img_url字符包含'经'执条件1,否则执行条件2
update a set a.lon=charindex('经',a.img_url) city_locate a,inserted b where a.id=b.id --条件1
elseupdate a
set a.lat=charindex('纬',a.img_url) city_locate a,inserted b where a.id=b.id --条件2
end
end
CREATE trigger TR_city_locate
on dbo.city_locate for insert,update
as
beginif (1=0) --想在这写个条件语句,如果a.img_url字符包含'经'执条件1,否则执行条件2
update a set a.lon=charindex('经',a.img_url) city_locate a,inserted b where a.id=b.id --条件1
elseupdate a
set a.lat=charindex('纬',a.img_url) city_locate a,inserted b where a.id=b.id --条件2
end
end
CREATE trigger TR_city_locate on city_locate for insert,update
as
begin
if (charindex('经',img_url)>0)
update a set lon=charindex('经',a.img_url) from city_locate a,inserted b where a.id=b.id --条件1
else if(charindex('纬',img_url)>0)
update a set lat=charindex('纬',a.img_url) from city_locate a,inserted b where a.id=b.id --条件2
end
create trigger tr_city_locate
on dbo.city_locate
for insert,update
as
update a
set lon=(case when charindex('经',b.img_url)>0 then charindex('经',b.img_url) else lon end),
lat=(case when charindex('纬',b.img_url)>0 then charindex('纬',b.img_url) else lat end)
from city_locate a,inserted b
where a.id=b.id;
go