Select TOP sql statement with date datatypes

J

J. Muenchbourg

I would like to grab the earliest date of any of the records that gets
drawn from this SQL statement:

datesql = "SELECT top 1 gamedate FROM tblNFLGameData WHERE season = '" &
seasonZ & "' and gameweek = '" & gameweekZ & "'"

..this works for some of the simple stuff I'm doing now, but I am going
to have more involved calculations as far as dates and such. Does
"Select Top (whatever value and fieldname) FROM (table name)" have any
rules pertaining to Date data types in SQL?

Thanks
JMuench
 
L

Lance Wynn

If you are looking for the earliest be sure to order by that field.


I would like to grab the earliest date of any of the records that gets
drawn from this SQL statement:

datesql = "SELECT top 1 gamedate FROM tblNFLGameData WHERE season = '" &
seasonZ & "' and gameweek = '" & gameweekZ & "'"

..this works for some of the simple stuff I'm doing now, but I am going
to have more involved calculations as far as dates and such. Does
"Select Top (whatever value and fieldname) FROM (table name)" have any
rules pertaining to Date data types in SQL?

Thanks
JMuench
 
T

Tom B

TOP X
takes the first X "rows" based on the rest of the query. So if your query
sorts by dates ascending, it takes the X oldest. If your query sorts by
dates descending, the X newest.
 
D

dlbjr

FYI

Be aware the TOP function of SQL will not work against many versions of
Oracle.

-dlbjr

invariable unerring alien
 
A

Aaron Bertrand - MVP

Well, the OP was using TOP initially, so I assume he is using a database
that supports it...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top