Results 1 to 3 of 3

Thread: Need a date in between min and max

  1. #1
    Join Date
    Feb 2003
    Posts
    16

    Need a date in between min and max

    I have a table that stores dates of records that need to be reprocessed. Normally I would use MIN function to pick up the earliest date I need processed. Lately i've been finding at least one date is out of the norm. So instead of picking up the min I'd like to pick up the next in line.

    For example, the first date is 20090104 (which min would give me), then 20100403 then 20100404,20100405 but i want to pick up the next one.

    This is a night time process and I won't know which dates are in the table so I can't hardcode. I'm only checking if the 1st date returned by the min is greater than 30 days from current day. Is there any way of doing this?

    Thanks,
    Ninel

  2. #2
    Join Date
    Sep 2005
    Posts
    168
    a better description of the issue would result in a more helpful reply.
    Do you need the minimum date that falls in the range of today-30 days?
    it could be:
    DECLARE @lower_date_limit DATETIME
    SET @lower_date_limit = DATEADD(dd, -30, CAST(CONVERT(CHAR(8), GETDATE(), 112) AS DATETIME))

    SELECT MIN(mydate)
    FROM myschema.mytable
    WHERE mydate >= @lower_date_limit

    --HTH--

  3. #3
    Join Date
    Jan 2010
    Posts
    37
    I agree with Ninel, what is it you are actually looking for? Are you needing just one record returned, or all that fit a certain criteria?

Posting Permissions

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