Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7061313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T04:27:31+00:00 2026-05-28T04:27:31+00:00

I am running a sql query to return the largest value in a column

  • 0

I am running a sql query to return the largest value in a column back to the program.

The sql query i run is..

select MAX([Line No]) from table

I am using sql server 2008.

The table has 3 rows, ‘Line No’ has values 50, 90, 100

the max value i expect to be returned is 100,
but im getting 90..why?

EDIT:

  string LineNo = "0";

   //LineNo
   string SQLlineno = "select MAX(CAST([Line No] As Int)) from Saved_Order_Import where [order no] = '"
                      + ordernumber + "'";
   SqlCommand myCommandlineno = new SqlCommand(SQLlineno, myConnection);
   SqlDataReader readerline;
   try
   {
       readerline = myCommandlineno.ExecuteReader();
       if (readerline.HasRows)
       {
           while (readerline.Read())
           {
               try
               {
                   if (readerline.GetString(0) != null)
                   {
                       LineNo = (readerline.GetString(0) + 10).ToString();
                   }
               }
               catch (Exception ex) { return "{\"error\":\"line : " + ex.ToString() + "\"}"; }
           }
       }
       readerline.Close();
   }
   catch (Exception ex)
   {
      // return "{\"error\":\"Other One11" + ex.ToString() + "\"}";
   }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T04:27:32+00:00Added an answer on May 28, 2026 at 4:27 am

    Your column is likely not a numeric type but a string type (char, nchar, varchar, nvarchar). So, it is sorting alphabetically, and 9 comes after 1.

    The easiest thing is to change to the correct data type for that column. If you can’t do that, you’ll need to cast back to the correct type inside the MAX.

    E.g.,

    select max(cast ([Line No] as int)) 
    from table 
    

    If you have some values in that column that cannot be converted to a number that you want to filter out, you can do:

    select max(cast ([Line No] as int)) 
    from table 
    where isnumeric([Line No]) = 1
    

    Or, to only show the non-numeric values, so you can fix them, you could do:

    select *
    from table 
    where isnumeric([Line No]) = 0
    

    For more robust integer detection, see this article: Can I Convert This String to an Integer?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am running the following SQL query: SELECT * FROM cms_albums WHERE id IN
the current SQL query works fine locally on MAMP 1.8.4 running MySQL 5.1.37. SELECT
I want to return the 10 most common words from a query in SQL
We've a table with a varchar2(100) column, that occasionally contains carriage-return & line-feeds. We
Need help from you all in writing up this query. Running SQL 2005 Standard
I am running an SQL pass-through query in SAS. When I run it on
I'm running SQL query for MySQL server with ... where name in (term1,term2,term3) I
I'm running an SQL query against a mainframe DB2 database using the OdbcDataReader class
I am running a sql in PHP query that is dieing with the mysql_error()
I recently discovered that a sql query that was running fine earlier is now

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.