Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql question

Status
Not open for further replies.

room24

Programmer
Dec 28, 2003
83
JM
is there a date function the can return from a list of dates the next date which is the first one greater than some "input date"


example

table A input date = 2002-01-02 23:59:59.000

2001-08-22 23:59:59.000
2001-09-02 23:59:59.000
2002-01-02 23:59:59.000
2002-02-04 23:59:59.000
2002-03-19 23:59:59.000
2002-04-31 23:59:59.000


this function would return 2002-02-04 23:59:59.000
because it is the first date greater than input date
 
SELECT top 1 dateField FROM myTable WHERE datefield > @inputDate

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
OOPPS


SELECT top 1 dateField FROM myTable WHERE datefield > @inputDate ORDER BY dateField ASC

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Or are you just trying to add a day?


SELECT dateAdd(d,1,@inputDate)

Programming today is a race between software engineers striving to build better and bigger idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning. - Rick Cook (No, I'm not Rick)

zen.gif
 
Try this:
SELECT TOP 1
YourDateField From YourTableName Where YourDateField > YourInputDate
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top