各位朋友,SQL库里面的数据如图1,现在当用户进行排序操作后,希望DBGRIDEH表格可以显示出如图2的排序方法。图1:批号 牌号
7-06004 2-3
7-06004 10-11-12
7-06004 4-5
7-06004 112-113
7-06004 1
7-06004 6-7-8
7-06004 9
请问能否将以上的数据,按牌号里面,各个数字的大小来排序,最后的顺序如下图2:批号 牌号
7-06004 1
7-06004 2-3
7-06004 4--5
7-06004 6-7-8
7-06004 9
7-06004 10-11-12
7-06004 112-113请各位朋友赐教,多谢!
7-06004 2-3
7-06004 10-11-12
7-06004 4-5
7-06004 112-113
7-06004 1
7-06004 6-7-8
7-06004 9
请问能否将以上的数据,按牌号里面,各个数字的大小来排序,最后的顺序如下图2:批号 牌号
7-06004 1
7-06004 2-3
7-06004 4--5
7-06004 6-7-8
7-06004 9
7-06004 10-11-12
7-06004 112-113请各位朋友赐教,多谢!
解决方案 »
- ★★★Delphi控件繁簡體自動轉換問題!!!
- 如何检测字符串中是否有某些字符
- 求delphi所有类的名称
- 紧急呼救Treevierw的问题,请交各位大哥!
- 解决此问题,100分相送!
- 请问各位,我做了一个控件如何可以在网上出售呢??谢谢
- VCL中的一个Win32API的声明错误
- 我做了一个vcl控件,它从TEdit继承,我想如何改变它的在工具栏中的图标?在线等待。
- 小弟有难了,情兄弟姐妹们帮一下!!DELPHI 如呵取ACCESS库中TEXT类型的数据??????
- dbcombobox的下拉列表为什么在运行以后就不出现内容了呢?
- 请问两个数组或TStringList怎么进行与或非运算?在线等,谢谢!
- datetimepicker控件问题
order by [牌号]
else substring(dt1,0,charindex('-',dt1)) end)
试试
create table a (dt varchar(50),dt1 varchar(50))
insert a select '7-06004','1'
union all select '7-06004','10-11-12'
union all select '7-06004','112-113'
union all select '7-06004','2-3'
union all select '7-06004','4-5'
union all select '7-06004','9'
union all select '7-06004','6-7-8'
goselect * from a order by convert(int,case charindex('-',dt1) when 0 then dt1
else substring(dt1,0,charindex('-',dt1)) end) drop table a ----结果
dt dt1
7-06004 1
7-06004 2-3
7-06004 4-5
7-06004 6-7-8
7-06004 9
7-06004 10-11-12
7-06004 112-113
select kwph, ph from zzbfkb
order by
case when charindex('-',ph)>0 and isnumeric(substring(ph,1,charindex('-',ph)-1))=1 then cast(substring(ph,1,charindex('-',ph)-1) as int)
when charindex('-',ph)>0 and isnumeric(substring(ph,1,charindex('-',ph)-1))=0 then substring(ph,1,charindex('-',ph)-1)
when charindex('-',ph)=0 and isnumeric(ph)=1 then cast(ph as int)
else cast(substring(ph,1,len(ph)) as varchar) end
但当遇到这样的记录,系统就提示出错了,还望各位朋友继续赐教,多谢!!!
货物批号 牌号
7-03009 120A
服务器: 消息 245,级别 16,状态 1,行 1
将 varchar 值 '120A' 转换为数据类型为 int 的列时发生语法错误。
taxpayer大哥,衷心的谢谢您!!!现在问题终于解决了,下面的语句是从你的语句转化过来的
select kwph, ph from zzbfkb order by len(convert(varchar(50),case charindex('-',ph) when 0 then ph
else substring(ph,0,charindex('-',ph)) end)),
convert(varchar(50),case charindex('-',ph) when 0 then ph
else substring(ph,0,charindex('-',ph)) end)