日期:2014-05-19  浏览次数:20566 次

如何去掉整列内的中文.

如何去掉整列内的中文.
示例如下:

create   table   #test(names   nvarchar(50))

insert   into   #test   select(N 'asfe2中532 ')
insert   into   #test   select(N '要e2中vb53网站 ')

drop   table   #test

在线等待...


------解决方案--------------------


select replace(Convert(varchar,names), '? ', ' ') as names from #test

names
--------------------------------------------------------------
asfe2532
e2vb53

(2 row(s) affected)


------解决方案--------------------
if object_id( 'tbTest ') is not null
drop table tbTest
if object_id( 'fnTest ') is not null
drop function fnTest
GO
create table tbTest (names nvarchar(50))
insert into tbTest select N 'asfe2中532 '
insert into tbTest select N '要e2中vb53网站 '
GO
create function fnTest(@name nvarchar(50))
returns nvarchar(50)
as
begin
while PATINDEX( '%[吖-座]% ',@name) > 0
set @name = stuff(@name,PATINDEX( '%[吖-座]% ',@name),1,N ' ')
return @name
end
GO

SELECT dbo.fnTest(names) as name from tbTest

drop table tbTest
drop function fnTest

/*结果
name
-----------
asfe2532
e2vb53
*/