我想如果判一个字符串是否是否有汉字,实际应用中应包含全角字符。
那最简单了:
if len('字符串')=datalength('字符串')
print '不含'
else
print '含'
select * from table where len(field)<>datalength(field)
如果是纯汉字,类似大力的方法写个函数:
create function ifexistscnword(@str varchar(1000))
returns int
as
begin
declare @i int
set @i=0
while @str <>'' and @i<>1
begin
set @i=case when unicode(left(@str,1)) between 19668 and 19668+20902 then 1 else 0 end
set @str=right(@str,len(@str)-1)
end
return @i
end
----------------
select * from table where dbo.ifexistscnword(field)=1
select top 20902 code=identity(int,19968,1) into #t from
(select top 100 a=1 from syscolumns) as a,
(select top 100 a=1 from syscolumns) as b ,
(select top 10 a=1 from syscolumns) as c
create function 是汉字吗(@a nvarchar(4000))
returns bit
begin
declare @b bit
while @a<>'' and @b is null
begin
select @b=1 where unicode(left(@a,1)) between 19968 and 40870
set @a=right(@a,len(@a)-1)
end
return isnull(@b,0)
end
go