Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
239 views
in Technique[技术] by (71.8m points)

sql - SQL Server外来字符等于空字符串(SQL Server foreign characters equal empty string)

We have a query looking for empty values in a column, but it is returning results where the column is not empty.

(我们有一个查询,用于查找列中的空值,但它返回的结果是该列不为空。)

As an example, this query returns true:

(例如,此查询返回true:)

IF N'??????????????? ??????? ???????????????????? ?????????????????? ???????????' = N''
    PRINT 'true'
ELSE
    PRINT 'false';

I suspect it may be a collation issue, but I've tried forcing various collations and the result is still true.

(我怀疑这可能是排序规则问题,但是我尝试强制进行各种排序规则,结果仍然是正确的。)

IF N'??????????????? ??????? ???????????????????? ?????????????????? ???????????' = N'' COLLATE Arabic_CI_AI
    PRINT 'true'
ELSE
    PRINT 'false';
  ask by Joe Stefanelli translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The text you want to compare seems to be Khmer, not Arabic, so you should use a Khmer_100_* collation.

(您要比较的文字似乎是高棉语,而不是阿拉伯语,因此您应该使用Khmer_100_*归类。)

Have a look at this TSQL snippet

(看看这个TSQL片段)

declare @coll table (
    name nvarchar(50),
    khmerSupported bit
)

declare @text nvarchar(200) = N'??????????????? ??????? ???????????????????? ?????????????????? ???????????'

declare @name nvarchar(50), @sql nvarchar(500)

declare c cursor for 
select name from sys.fn_helpcollations()
where name like 'khm%'

open c

fetch c into @name
while @@fetch_status = 0 begin

set @sql = 'select ''' + @name + ''', case when @text = N'''' COLLATE ' + @name + ' then 0 else 1 end'
print @sql
    insert into @coll (name, khmerSupported)
    exec sp_executesql @sql, N'@text NVARCHAR(200)', @text=@text

    fetch c into @name
end

close c
deallocate c

select Name, KhmerSupported from @coll

and experiment with the collations query.

(并尝试使用归类查询。)

Use select Name, KhmerSupported from @coll where KhmerSupported=1 to find all collations supporting Khmer comparison.

(使用select Name, KhmerSupported from @coll where KhmerSupported=1查找所有支持高棉语比较的排序规则。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...