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)
 Why not working?

Author  Topic 

lovehui
Yak Posting Veteran

60 Posts

Posted - 2009-04-14 : 14:13:27


ALL order by convert(int,DeptNum) ASC

I have a sql


select * from ta where Dept=ALL order by convert(int,DeptNum) ASC

DeptNum has type varchar(50).

Thanks

DonAtWork
Master Smack Fu Yak Hacker

2167 Posts

Posted - 2009-04-14 : 14:19:57
[code] where Dept= ' ALL ' order by convert(int,DeptNum) ASC [/code]

EDIT: also, you might want to make sure that DeptNum CAN be converted into an INT.

[Signature]For fast help, follow this link:
http://weblogs.sqlteam.com/brettk/archive/2005/05/25.aspx
Learn SQL or How to sell Used Cars
For ultra basic questions, follow these links.
http://www.sql-tutorial.net/
http://www.firstsql.com/tutor.htm
http://www.w3schools.com/sql/default.asp
Go to Top of Page

Kokkula
Starting Member

41 Posts

Posted - 2009-04-15 : 02:53:32
Hello,

For this to achieve DeptNum field should be numeric. Try this

SELECT *
FROM TableName
WHERE Dept = 'ALL'
AND ISNUMERIC(DeptNum) = 1
ORDER BY CONVERT(INT,DeptNum) ASC

Hope helpful...


Thanks,
Pavan
Go to Top of Page
   

- Advertisement -