Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 Order by

Author  Topic 

Todd2006
Starting Member

18 Posts

Posted - 2009-02-24 : 21:18:20
Hi,

I have this problem I am trying to get the Max score for the subject maths and right now its not working properly

the records are like this

234
145
34
43
30
21
134
167

it gives me the output as 30

can someone tell me whats wrong with this query


strmax="SELECT Name, Math_Prof, Maths_Points FROM Scores where subject_Id ='" & getid & "' order by Maths_Points desc"


Todd2006
Starting Member

18 Posts

Posted - 2009-02-24 : 22:41:56
if i change the desc to asc then it shows me

21

which is right

but if i use the desc it doesnt work

any idea

Go to Top of Page

Nageswar9
Aged Yak Warrior

600 Posts

Posted - 2009-02-24 : 22:45:43
can u post ur full table structure and Expected Output
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-02-25 : 03:01:06
It is becuase your column is of character datatype. Cast it to INT

ORDER BY CAST(col as INT)

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-02-25 : 09:49:52
ORDER BY col*1
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2009-02-25 : 09:53:35
http://sqlblogcasts.com/blogs/madhivanan/archive/2008/07/21/ordering-interger-values-stored-in-varchar-column.aspx

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -