mssql数据库有一个表table,里面有很多行数据,其中,有一些行数据是中文,有些行数据是英文

来源:百度知道 编辑:UC知道 时间:2024/05/30 04:05:20
我想只select所有数据列a为中文的数据。如何实现?

例如
id a
1 en
2 中文啊阿飞的卡拉季
3 abcddd
4 又是中文啊啊啊

只提取2和4两行

--判断字符串是否包含中文
Create Function HaveChinese (@Str varchar(4000))
returns bit
as
begin
declare @IsHave bit
if @Str like '%[啊-座]%'
set @IsHave = 1
else
set @IsHave = 0
return @IsHave
end

--判断字符串是否全部是中文
Create Function HaveChinese (@Str varchar(4000))
returns bit
as
begin
declare @IsHave bit,@i int,@len int,@all int
select @i=1
select @len=len(@str)
select @all=0
while @i<=@len
begin
if substring(@str,@i,1) like '%[啊-座]%'
set @all=@all+1
else
set @all=@all+0
select @i=@i+1
end
if @all=@len
select @IsHave=1
else
select @IsHave=0
return @IsHave
end

go

select * from table where dbo.HaveChinese(a)=1

看你自己的需要,如果需要包含中文的话用第一个函数,如果需要全部是中文的话用第二个函数

以上,希望对你有所帮助!

not in '