locked
How return max value in LINQ, please?

    Question

  • I have the following values in my AnimalTag table under the column AnimalTagNumber.

     

    123456
    234567
    345678
    D00001
    D00002
    D00003

     

    In LINQ (preferably VB but C# if that's all I can get), how can I select the Max (although it is not numeric) where the first character is "D"?

     

    I.e. for the above I'm wanting to return D00003.

     

    Thanks for any assistance,
    Ron

    Tuesday, March 04, 2008 4:26 PM

Answers

  • Hi rcook349,

     

    You can use the following LINQ query statement, I have tested it in SQL server 2005, it works well.

     

                  

    Code Snippet

      var max_Query =
                   (from tab1 in mydb.AnimalTag              
                   select tab1.AnimalTagNumber).Max();

                  
                   Console.WriteLine(max_Query);

     

     

                   

    Regards,

    Xun

    Friday, March 07, 2008 4:49 AM

All replies

  • Hi rcook349,

     

    You can use the following LINQ query statement, I have tested it in SQL server 2005, it works well.

     

                  

    Code Snippet

      var max_Query =
                   (from tab1 in mydb.AnimalTag              
                   select tab1.AnimalTagNumber).Max();

                  
                   Console.WriteLine(max_Query);

     

     

                   

    Regards,

    Xun

    Friday, March 07, 2008 4:49 AM