本文介绍了在asp.net 4.0中的网格视图中按降序对记录进行排序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的朋友,

我在asp.net 4.0的网格视图中显示排序记录时遇到问题.我已经在日期基础上在查询中放置了order by子句,之后又没有序列号,例如:-

"按[日期] desc,[序列号] desc从[表名]顺序中选择*".

但是我的问题是,它按日期对数据进行排序,但是当涉及到同一日期的记录排序时,序列号如37/1/1/ROR/20和37/1/1/ROR/9,它实际上将37/1/1/ROR/9放在37/1/1/ROR/20之前,因为sql server 2008在单个数字后填充零,因此使序列号成为
.
37/1/1/ROR/9到37/1/1/ROR/90 ,因此放在37/1/1/ROR/20之前.

最后排序的列表出错了.

有人可以帮我吗?

谢谢

Varun Sareen

Dear Friends,

I have an issue showing sorted record in grid view in asp.net 4.0. I have put order by clause in the query on date basis and after that on serial no basis like:-

"select * from [TableName] order by [Date] desc, [SerialNo] desc".

But my problem is that it sorts the data according to date but when it comes to sorting of record on the same date where serial no are like 37/1/1/ROR/20 and 37/1/1/ROR/9, It actually puts 37/1/1/ROR/9 before 37/1/1/ROR/20 as sql server 2008 pads a zero after a single digit hence making the serial no.

37/1/1/ROR/9 to 37/1/1/ROR/90 therefore putting it before 37/1/1/ROR/20.

And in the end the sorted list goes wrong.

Can anyone help me in this.?

Thanks

Varun Sareen

推荐答案

SELECT * FROM [TableName] ORDER BY [Date] DESC, CAST(REPLACE([SerialNo], '37/1/1/ROR/','') AS BIGINT) DESC


我的建议是,如果您通过拆分SerialNo列来创建其他列,那么将很容易处理这些事情,而不是上面的方法.

示例:


My suggestion is if you create additional columns by splitting the SerialNo column then it will be easy to handle these kind of things instead of above way.

Example:

SerialNo      - AC1 AC2 AC3 AC4 AC5
37/1/1/ROR/90 - 37  1   1   ROR 90


注意:交流-附加列


这篇关于在asp.net 4.0中的网格视图中按降序对记录进行排序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-30 07:00