Finding MAX value from emp_id column using SQL query?

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:-

select MAX(emp_id) from table_name
View Answers

March 28, 2011 at 2:27 PM

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

Assuming that it only holds digits, try select max(convert(int, empid)) from tablename

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


March 28, 2011 at 2:40 PM

Hi,

Is empid numeric? because '9' is bigger than '11' or '57' if empid string type.So first check that emp_id is numeric or String.









Related Tutorials/Questions & Answers:
Finding MAX value from emp_id column using SQL query?
SQL Aggregate Max
Advertisements
SQL Max Count
SQL add column default value
SQL add column default value
SQL Alter Column Default Value
how to get values for same column name from two different tables in SQL
SQL Alter Column Default Value
Find Value of Column
Retrieve data from database by using sql tag of JSTL SQL library
SQL Aggregate Max
How to add value from sql server in dropdownlist
get details of employee after enter the emp_id
get details of employee after enter the emp_id
Find max and min value from Arraylist
Validating Emp ID Reply - JSP-Servlet
How to retrieve data from database by using combo box value in jsp? - JSP-Servlet
Hibernate criteria query using Max()
How to read value from xml using java?
sql add comment to column
rename the column in sql
How to insert multiple drop down list data in single column in sql database using servlet
select result from three tables using sql.
select value from autocomplete textbox using jquery in jsp from database.
select value from autocomplete textbox using jquery in jsp from database.
SQL Alter Column Name
Using Min, Max and Count on HQL.
Finding smallest value, then the next etc
SQL Alter Column
SQL Add Column Position
Mysql Max Date
Mysql Max Date
Max()
Max()
Auto generated column in sql 5.0 - SQL
SQL Add Column
SQL Add Column Int
SQL Alter Column Syntax
SQL Alter Column Name
populating textbox value from the database using onchange function,
SQL All Column Names
How to insert image in sql database from user using servlet
Selecting value from autocomplete textbox using jquery in jsp
adding some value to new column
SQL Add Column Position
SQL Add Column
Java BigInteger max value
how to show effect (visual) on jsp page using value from database
SQL Alter Column
Problem passing a value from one jsp to another using href

Ads