34,874
社区成员
发帖
与我相关
我的任务
分享
print @@version
if '-' < '1' print '''-'' < ''1'''
if '-a' < '1a' print '1'
if '-a' = '1a' print '2'
if '-a' > '1a' print '3'
if '-a' > '1a' print '''-a'' > ''1a'''
drop table #test
create table #test (test varchar(20) )
insert #test
select '-1147721273'
union all select '1147721284'
union all select '114772125'
union all select 'a1'
union all select 'a3'
union all select '-a2'
union all select 'a-2'
union all select 'a-4'
union all select 'a4'
select * from #test order by 1
/* 执行结果
Microsoft SQL Server 2008 (RTM) - 10.0.1600.22 (X64)
Jul 9 2008 14:17:44
Copyright (c) 1988-2008 Microsoft Corporation
Enterprise Edition (64-bit) on Windows NT 6.1 <X64> (Build 7601: Service Pack 1) (VM)
'-' < '1'
3
'-a' > '1a'
(9 行受影响)
(1 行受影响)
test
--------------------
114772125
-1147721273
1147721284
a1
-a2
a-2
a3
a4
a-4
(9 行受影响)
(1 行受影响)
*/

而_BIN二进制那个排序是比较死板。。。
)
是不是如果是用默认[/quote]
我也是偷懒,用默认的,但是遇到问题要知道是怎么回事,怎么解决,所以具体解决方法还要看你的需求。
比如我司有一个表中某数据是区分大小写的,且是PK,所以就要把那一列改为CS_AI
)
是不是如果是用默认
[/quote]
查看一下你的排序 规则 是什么 select SERVERPROPERTY('Collation')
我不确定它会不会影响 字符的ascii 值,之前没遇到过
反正是个中文windows,没留意过这个。试一下先[/quote]
你可以在建表的时候就指定排序规则,比如:
create table #test (test varchar(20) collate Chinese_PRC_BIN)
以后这一列再遇到这种情况的时候不需要指定排序规则也会按照建表时的排序规则来做比较、排序
反正是个中文windows,没留意过这个。试一下先
with t as(
select '-1147721273' collate Chinese_PRC_BIN as col1
union all select '1147721284'
union all select '114772125'
union all select 'a1'
union all select 'a3'
union all select '-a2'
union all select 'a-2'
union all select 'a-4'
union all select 'a4')
select col1 from t order by col1