How to show the MIN Date Value in a query

  • After reading many posts, this is what I learned.

    SELECT MIN(StartDate) AS MinDate FROM Schedule WHERE WorkCenterID = 'LAY-W' AND ScheduleID = '5' GROUP BY StartDate

    It produces all three values.  I just want the Minimum Date Value to be returned.

     

    Thanks!

     

    Steve Anderson

  • If you want a single, minimum value returned, don't group the data.

    The above is all just my opinion on what you should do. 
    As with all advice you find on a random internet forum - you shouldn't blindly follow it.  Always test on a test server to see if there is negative side effects before making changes to live!
    I recommend you NEVER run "random code" you found online on any system you care about UNLESS you understand and can verify the code OR you don't care if the code trashes your system.

  • Exactly.  Just this:

    SELECT MIN(StartDate) AS MinDate

    FROM Schedule

    WHERE WorkCenterID = 'LAY-W' AND ScheduleID = '5'

    SQL DBA,SQL Server MVP(07, 08, 09) "It's a dog-eat-dog world, and I'm wearing Milk-Bone underwear." "Norm", on "Cheers". Also from "Cheers", from "Carla": "You need to know 3 things about Tortelli men: Tortelli men draw women like flies; Tortelli men treat women like flies; Tortelli men's brains are in their flies".

  • This was removed by the editor as SPAM

Viewing 4 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic. Login to reply