22,207
社区成员
发帖
与我相关
我的任务
分享
;with st
as
(
select '荣氏' as name union all
select '金龙鱼' union all
select '鹭滨'
),
tb
as
(
select 'm0001汁果苹氏荣' 品名
)
select tb.品名,
case when exists(select 1 from st where reverse(tb.品名) like '%'+st.name+'%') then reverse(tb.品名)
else tb.品名 end as new_品名
from tb
/*
品名 new_品名
m0001汁果苹氏荣 荣氏苹果汁1000m
*/
;with 品名全部可选项列表(品名) as
(
select '荣氏橙汁酸奶(200ml)' union all
select '荣氏橙汁酸奶(500ml)' union all
select '荣氏橙乌龙茶(500ml)' --......
)
update t set 品名=reverse(tt.品名)
from t join 品名全部可选项列表 as tt on t.品名=reverse(tt.品名)
;
如果没有那只能自己整理出一个:
用select distinct t1.品名
from t t1,t t2
where t1.流水号<>t2.流水号 and t1.品名=reverse(t2.品名) and LEN(t1.品名)>1
这个语句,执行后,每两行一对,手工挑出正确的再,整理出一个列表来。再按第一种情况update