473,387 Members | 1,897 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Select TOP sql statement with date datatypes

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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #1
5 13177
If you are looking for the earliest be sure to order by that field.
"J. Muenchbourg" <jo*****@canada.com> wrote in message
news:%2********************@TK2MSFTNGP10.phx.gbl.. .
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Jul 19 '05 #2
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.
"J. Muenchbourg" <jo*****@canada.com> wrote in message
news:%2********************@TK2MSFTNGP10.phx.gbl.. .
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #3
TOP makes no sense without an ORDER BY clause.


"J. Muenchbourg" <jo*****@canada.com> wrote in message
news:#D**************@TK2MSFTNGP10.phx.gbl...
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

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Jul 19 '05 #4
FYI

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

-dlbjr

invariable unerring alien
Jul 19 '05 #5
Well, the OP was using TOP initially, so I assume he is using a database
that supports it...

"dlbjr" <do******@do.u> wrote in message
news:#D**************@TK2MSFTNGP12.phx.gbl...
FYI

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

-dlbjr

invariable unerring alien

Jul 19 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: KePaS | last post by:
I,ve got the following Script to Use on MS Access. So far it works just fine, but I want to set "Auto-Increment" to the field "test16_auto_long", but I don't know the expression Access wants to...
4
by: Polly | last post by:
I had a macro that ran a parameter query and created and opened an Excel file with the system date as part of the file name, but I had to change the file name by hand. So I converted the macro to...
3
by: Shelby Cain | last post by:
The select statements return different data for most_commons_vals depending on whether n_distinct is included in the select clause or not. I only seem to get the behavior below against int8...
3
by: Kall, Bruce A. | last post by:
I've look for a solution to this, but have only been able to find solutions to delete duplicate entries in a table by deleting entries not returned by SELECT DISTINCT. What sql should I use to...
3
by: divya | last post by:
Hi, I have a table tblbwday with 2 fields Name and Birthday.I have written this script for displaying evryday names of the people on that day. <% set objConn...
10
by: DontellTrevell via AccessMonster.com | last post by:
HELP!!....I need to calculate the numer of days elapsed between two field. But, the date format is YYYYMMDD. How can i accomplsh this? -- Dontell Trevell Message posted via AccessMonster.com...
0
by: djflow | last post by:
Hi! II was wondering if you can help me with SQL query.. Below 7 separated select query works fine(only when they are retrieved separately) But I want to combined them together and so that i...
5
JustJim
by: JustJim | last post by:
I think I've just bumped into the limits of the Having Clause (Help file says 40 expressions, Mary says 99 and I know who I trust). The question is, what happens if you overload the select......
2
by: paulmitchell507 | last post by:
I think I am attempting a simple procedure but I just can't figure out the correct syntax. My asp (classic) page runs a SELECT query to obtain dates and ID's from 2 tables uSQL = "SELECT...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.