|
发表于 2011-10-31 10:57:43
|
显示全部楼层
Re:^SQL2000字符过滤
SQL code declare @t table([item_name] nvarchar(50))
Insert @t
select N'12g旺仔牛奶' union all
select N'500ml*15统一绿茶' union all
select N'康师傅108g泡面' union all
select N'来一桶泡面208g' UNION ALL
select N'10斤面巴' union all
select N'1.05公斤面巴' union all
select N'1.7kg洗衣粉' union all
select N'4.75kg洗衣粉'union ALL
select N'1.5L金龙鱼油' union all
select N'1.05L金龍鱼油'
UPDATE @t
SET [item_name]=
CASE WHEN PATINDEX(N'%[a-zA-Z0-9*/+.-]%',[item_name])=1
THEN substring([item_name],PATINDEX(N'%[^a-zA-Z0-9*/+.-]%',[item_name]),LEN([item_name]))+LEFT([item_name],PATINDEX(N'%[^a-zA-Z0-9*/+.-]%',[item_name])-1)
ELSE
STUFF([item_name],PATINDEX(N'%[a-zA-Z0-9*/+.-]%',[item_name]),
LEN([item_name])-(PATINDEX(N'%[a-zA-Z0-9*/+.-]%',REVERSE([item_name]))+PATINDEX(N'%[a-zA-Z0-9*/+.-]%',[item_name]))+2,'')
+
SUBSTRING([item_name],PATINDEX(N'%[a-zA-Z0-9*/+.-]%',[item_name]),
LEN([item_name])-(PATINDEX(N'%[a-zA-Z0-9*/+.-]%',REVERSE([item_name]))+PATINDEX(N'%[a-zA-Z0-9*/+.-]%',[item_name]))+2)
end
WHERE PATINDEX(N'%[a-zA-Z0-9*/+.-]%',REVERSE([item_name]))>1
UPDATE @T SET [item_name]=REPLACE([item_name],N'公斤','')+N'公斤' WHERE [item_name] LIKE N'%公斤%'
UPDATE @T SET [item_name]=REPLACE([item_name],N'斤','')+N'斤' WHERE 'A'+[item_name] LIKE N'%[^公]斤%'
SELECT * FROM @T
/*
旺仔牛奶12g
统一绿茶500ml*15
康師傅泡面108g
来一桶泡面208g
面巴10斤
面巴1.05公斤
洗衣粉1.7kg
洗衣粉4.75kg
金龍鱼油1.5L
金龙鱼油1.05L
*/ |
|