Results 1 to 2 of 2

Thread: Find Minimum and Maximum

  1. #1

    Thread Starter
    Member
    Join Date
    Oct 2009
    Posts
    58

    Find Minimum and Maximum

    Dear Experts

    SqlServer Table1 has data as follows

    Sno-------date
    1------01/01/2010
    8------01/01/2010
    1------02/01/2010
    5------02/01/2010
    2------18/01/2010
    9------18/01/2010
    3------18/01/2010
    1------03/01/2010
    6------03/01/2010

    My questions are:

    1) I want to display the SMALLEST Date into textbox1 which is 01/01/2010
    2) I want to display the BIGGEST Date into textbox2 which is 18/01/2010
    3) I want to display the BIGGEST SNO against date 18/01/2010 into textbox3 which is 9
    4) I want to display total records against date 18/01/2010 into textbox4 which is 3


    Please help

  2. #2
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Find Minimum and Maximum

    If you want to do this using SQL code, so you only retrieve those specific values from the database, then use something like:
    SQL Code:
    1. SELECT MIN([Date]) FROM Table1
    There are other native functions too, like MAX and COUNT, that will be useful to you. If you want to get the min or max for a subset then you simply add a WHERE clause, e.g.
    SQL Code:
    1. WHERE [Date] = @Date
    If you already have a populated DataTable then you can use its Compute method to do similar things.

    For future reference, if you're specifically asking for information on SQL code then that would belong in the Database Development forum.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width