# Database Discussions > Microsoft SQL Server 2005 >  Need a date in between min and max

## Ninel

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

----------


## mikr0s

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--

----------


## J013

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?

----------

