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
301 views
in Technique[技术] by (71.8m points)

sql - TSQL Select national characters issue with the range

I'm on SQL Server 2016 with default settings, and can't understand whey this line 4 doesn't catch my weird character ? which A with the roof. It's matched by [a-z] range, never thought that it would be the case. Is the any solution to work it out with the range ? In my example below I expect to display single record, but line 4 doesn't allow me do so. Is line 5 with the list the only solution??? Interesting that CHAR(13) is of of the range and works fine.

DECLARE @a VARCHAR(10) = CHAR(13) +'Delta',   @b NVARCHAR(20) = '?' + 'Hotel';
SELECT @a A, LEN(@a) LenA, @b B, LEN(@b) LenB  
       ,CASE WHEN @b < 'A' THEN 'LessA'  ELSE CASE WHEN @b > 'Z' THEN 'GreaterZ' ELSE  '? Between' END END sw
WHERE 1=1
AND    @b NOT LIKE  '[A-Z]%'             --- Line 4:   <<< '?'   in the range [a-z] or [A-Z] , how I can only work with 26 English letter range ???
-- AND    @b NOT LIKE  '[ABCDEFHGW]%'    --- Line 5:   <<< is writing the list the only solution ?
-- AND    @b LIKE '?%' 
-- COLLATE Latin1_General_CS_AS

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

1 Reply

0 votes
by (71.8m points)
等待大神答复

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

...