sql 根据指定字符截取前面几个字符

时间:2022-10-11 15:30:55

1.找到指定字所在的位置并且减去多少是要截取的字符长度

CharIndex('元',product_name)-3)

2.截取

SUBSTRING(product_name, CharIndex('元',product_name)-3,3)

3.替换

REPLACE(SUBSTRING(product_name, CharIndex('元',product_name)-3,3),'- ','')

 

 

 

REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(REPLACE(SUBSTRING(old_package, CharIndex('元',old_package)-3,3),' ',''),'_',''),'户',''),'包',''),'网包',''),'餐',''),'套餐',''),'-',''),'套',''),'网','')