Click here to Skip to main content
15,888,610 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted
Comments
BELGIUMsky 23-Apr-14 2:41am    
Did you save the numbers as text?

because if you follow the instructions for a column integer like in the following url(see url in solution):
<a href="https://dev.mysql.com/doc/refman/5.0/en/sorting-rows.html">sorting rows</a>[<a href="https://dev.mysql.com/doc/refman/5.0/en/sorting-rows.html" target="_blank" title="New Window">^</a>]

you get the result you want
DamithSL 23-Apr-14 3:58am    
what is your database?

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.
 
Share this answer
 
v2
Comments
Jagadisha_Ingenious 23-Apr-14 2:58am    
@BELGIUMSKY: I have entered only numbers in the text format in the WindowsNo column, as shown in the table. I have not added any characters in that column so can you plz tell how to do it in such case.....?
BELGIUMsky 23-Apr-14 3:06am    
Do you know the data type of the column?

and can you have a try of the (field + 0 ) converts the text/character in the field into an integer?
to know for sure it doesn't work in your case?
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month


CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900