Sql排序 - MS-SQL Server / 基础类
我的Tblworkbill表的数据如下:
id workbillno ..................
1 1
2 6
3 a1
4 c2
5 2
6 aa
7 a2
8 5
9 7
10 d3
11 b1
. .
. .
. .
. .
如何将workbillno排序为:
1
2
5
6
7
a1
a2
b1
c2
d3
aa
SQL code:
--> 测试数据:[TB]
if object_id('[TB]') is not null drop table [TB]
create table [TB]([id] int,[workbillno] varchar(2))
insert [TB]
select 1,'1' union all
select 2,'6' union all
select 3,'a1' union all
select 4,'c2' union all
select 5,'2' union all
select 6,'aa' union all
select 7,'a2' union all
select 8,'5' union all
select 9,'7' union all
select 10,'d3' union all
select 11,'b1'
create function dbo.f_ASCII(@s varchar(50)) returns int
as
begin
declare @i int
set @i=0
while len(@s)>0
begin
set @i=@i+ASCII(left(@s,1))
set @s=right(@s,len(@s)-1)
end
return @i
end
go
select * from TB order by dbo.f_ASCII(workbillno)
/*
id workbillno
----------- ----------
1 1
5 2
8 5
2 6
相关问答:
大家帮忙看看这2个sql语句哪个查询的速度更快点。谢谢帮忙。比较着急。在做性能测试。
select * from
表A LEFT OUTER JOIN 表B ON (表A.id || ' ' =表B.id) ,表C , 表D, 表E
Where其他条件
select * ......
环境:1.win2003server+oracle9i
2.oracle9i字符集为AMERICAN_AMERICA.WE8ISO8859P1
3.oracle sql developer版本 1.5.5
现象描述: 1.在sql developer 中查询oracle中的某个表,中文全部显示为乱码。
......
type Exception report
message
description The server encountered an internal error () that prevented it from fulfilling this request.
exception
org.apache.jas ......
table1:
uID uName
1 小李
2 小张
table2:
pID uID type
1 1 H1
2   ......
现在有a1,a2两表
a1
id name aa cc
001 aaaa bbb cc
002 bbb bbb bbb
003 ccc ccc ccc
004 ddd ddd ddd
005 eee eee eee
a2
id ida2 ff b ......