472,143 Members | 1,575 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,143 software developers and data experts.

Finding MAX value from emp_id column using SQL query?

I need to select maximum of the Emp_id values from SQL server 2005 table.I was using the command which selects max value till 10 but after that it fails to pick max value of emp id from the table.(Actually it picks up Max value using by looking at 1st digit only,so till 9 its fine, but after that it shows 9>11 or 9>57 etc.So please tell me SQL query for finding max value in Emp id column.Thanx.
MY sql query used:-
Expand|Select|Wrap|Line Numbers
  1.     select MAX(emp_id) from table_name
  2.  
Mar 28 '11 #1

✓ answered by gpl

Im guessing that your emp_id column is not a numeric one!

Assuming that it only holds digits, try
select max(convert(int, emp_id)) from table_name

Or convert the whole column to a numeric type .. in future, it would be helpful if you posted the table definition too!

2 3190
gpl
152 100+
Im guessing that your emp_id column is not a numeric one!

Assuming that it only holds digits, try
select max(convert(int, emp_id)) from table_name

Or convert the whole column to a numeric type .. in future, it would be helpful if you posted the table definition too!
Mar 28 '11 #2
thank you sir...problem solved.thanx a lot brother
Mar 28 '11 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

1 post views Thread by Andrew Slentz | last post: by
reply views Thread by =?Utf-8?B?Y2NfY3Jhc2g=?= | last post: by
reply views Thread by =?Utf-8?B?VG9ueSBBLg==?= | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.