-->Title:生成測試數據
-->Author:wufeng4552
-->Date :2009-09-21 09:02:08
--unicode从19968到40868
if object_id('dbo.get_china_str')is not null drop function dbo.get_china_str
go
create function dbo.get_china_str
(
@str nvarchar(200)
)
returns nvarchar(200)
as
begin
declare @i int
set @i=1
while @i<=len(@str)
begin
if len(unicode(substring(@str,@i,1)))<5
begin
set @str=stuff(@str,@i,1,'');
end
else
set @i=@i+1;
end
return @str
end
go
select dbo.get_china_str(N'UNION ALL SELECT 我们都是中国人,都是炎黄子孙,都是龙人传人')
/*
我们都是中国人,都是炎黄子孙,都是龙人传人
(1 個資料列受到影響)
*/
--提取中文
IF OBJECT_ID('DBO.CHINA_STR') IS NOT NULL
DROP FUNCTION DBO.CHINA_STR
GO
CREATE FUNCTION DBO.CHINA_STR(@S NVARCHAR(100))
RETURNS VARCHAR(100)
AS
BEGIN
WHILE PATINDEX('%[^吖-座]%',@S) > 0
SET @S = STUFF(@S,PATINDEX('%[^吖-座]%',@S),1,N'')
RETURN @S
END
GO
PRINT DBO.CHINA_STR('呵呵ABC123ABC')
GO