日期:2014-05-17 浏览次数:20714 次
字段a 字段。。。。 2.3 12.33 &11.3 中文字24.3中文字 22.02 NULL 0.7-1.0 6.2
字段a 字段。。。。 2.3 12.33 [color=#FF0000]11.3[/color] [color=#FF0000]24.3[/color] 22.02 NULL [color=#FF0000]1.0[/color] 6.2
--提取非汉字 IF OBJECT_ID('dbo.fn_china_word') IS NOT NULL DROP FUNCTION dbo.fn_china_word GO CREATE FUNCTION dbo.fn_china_word(@S NVARCHAR(100)) RETURNS VARCHAR(100) AS BEGIN WHILE PATINDEX('%[吖-座]%',@S) > 0---去掉 ^ 就是取非汉字 SET @S = STUFF(@S,PATINDEX('%[吖-座]%',@S),1,N'') RETURN @S END GO if object_id('[Test]') is not null drop table [Test] go create table [Test]([字段a] nvarchar(30)) go insert into [Test] select '2.3' union all select '12.33' union all select '&11.3' union all select N'中文字24.3中文字' union all select '22.02' union all select NULL union all select '0.7-1.0' union all select '6.2' select case when [字段a] like '%&%' then '[color=#FF0000]'+replace([字段a],'&','')+'[/color]' when [字段a] like '%[吖-座]%' then '[color=#FF0000]'+dbo.fn_china_word([字段a])+'[/color]' when [字段a] like '%-%' then '[color=#FF0000]'+substring([字段a],charindex('-',[字段a])+1,len([字段a])-charindex('-',[字段a]))+'[/color]' else [字段a] end from [Test] /* (8 row(s) affected) ---------------------------------------------------------------------------------------------------------------- 2.3 12.33 [color=#FF0000]11.3[/color] [color=#FF0000]24.3[/color] 22.02 NULL [color=#FF0000]1.0[/color] 6.2 (8 row(s) affected) */