以升序检索数据库不是按顺序进行的 [英] Retrieving from database in ascending order is not coming in order

查看:77
本文介绍了以升序检索数据库不是按顺序进行的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,





任何人都可以告诉我们如何从特定列按升序从数据库中检索数据。



我有一张桌子,其中我将WindowsNo作为一列并以随机方式添加值。表格如下:



WindowsNo

1

3

12

13

2

5



我尝试使用从中选择WindowsNo表1其中ProjectName ='+ PjtName +'按WindowsNo asc排序我得到的结果是:



WindowsNo

1

12

13

2

3

5



我需要的是:



WindowsNo

1

2

3

5

12

13



如何获得这个....?



提前谢谢。

解决方案

你有没有将数字保存为文本?



因为如果您按照以下网址中的列整数的说明进行操作:

排序行 [ ^ ]



你得到你想要的结果。





如果是文字使用:



从Table1中选择WindowsNo,其中ProjectName = '+ PjtName +'order by(WindowsNo + 0)asc

(字段+ 0)将字段中的文本/字符转换为整数。


< blockquote>



请确认您的字段数据类型。如果它不是整数,那么请尝试以下查询:





从Table1中选择WindowsNo,其中ProjectName ='+ PjtName +'order by转换(int,WindowsNo)asc



注意:如果数据类型为text,image或ntext,则此解决方案将不适用。

Hi all,


Can anybody tell how to get retrieve data from database from a particular column in ascending order.

I have a table in which i have WindowsNo as a column & have added values in random manner. The table is shown below:

WindowsNo
1
3
12
13
2
5

I tried using "Select WindowsNo from Table1 where ProjectName='" + PjtName + "' order by WindowsNo asc " the result what i get is:

WindowsNo
1
12
13
2
3
5

What i require is:

WindowsNo
1
2
3
5
12
13

How to get this....?

Thanks in advance.

解决方案

Did you save the numbers as text?

because if you follow the instructions for a column integer like in the following url:
sorting rows[^]

you get the result you want.


If it is text use:

Select WindowsNo from Table1 where ProjectName='" + PjtName + "' order by (WindowsNo + 0) asc
The (field + 0 ) converts the text/character in the field into an integer.


Hi,

Please confirm your field datatype. If it is not integer then try following query :


Select WindowsNo from Table1 where ProjectName='" + PjtName + "' order by Convert(int,WindowsNo) asc

Note : This solution will not be applicable if datatype is text, image or ntext.


这篇关于以升序检索数据库不是按顺序进行的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆