ronipats
asked on
sql server 2008, stored procedure
I have one table in sqlserver2008. with two fields, name and rollno.
name varchar(100),
rollno varchar(50)
though i want to store numbers in rollno i have kept it as varchar(50). now my requiement is i want to sort all records based on rollno just like numbers.
say eg.
rollno
1
2
3
4
5
6
7
8
9
10
11
instead of
1
10
11
2
3
.....
how do i do that using sql qurey. Is ther any way to sort text fields just like numbers.
thanks
name varchar(100),
rollno varchar(50)
though i want to store numbers in rollno i have kept it as varchar(50). now my requiement is i want to sort all records based on rollno just like numbers.
say eg.
rollno
1
2
3
4
5
6
7
8
9
10
11
instead of
1
10
11
2
3
.....
how do i do that using sql qurey. Is ther any way to sort text fields just like numbers.
thanks
The above answer is correct but you may also do it as below
select Name,CONVERT(INT, rollno) rollno from mytable order by 2
select Name,CONVERT(INT, rollno) rollno from mytable order by 2
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
from mytable
order by cast(rollno as int)