Solved

What is a good way to compare the month portion of a date when using an SQL query?

Posted on 2006-07-11
4
190 Views
Last Modified: 2010-04-23
I have a database with a field containing dates in the format yyyy/mm/dd. I get the beginning and ending months from the user with 2 combo boxes. So let's say the user wants only the samples between SEP and OCT.  What is the correct SQL syntax to get this?  I'm looking for the '....' part of the Select statement below. I am using Access and VB.Net 1.1

Thank you in advance.


cboFMonth.Text = "SEP"
cboLMonth.Text = "NOV"
Dim strSQL as String =  "SELECT DateReceived WHERE DateReceived...."
0
Comment
Question by:IT_Steve
  • 2
4 Comments
 
LVL 3

Accepted Solution

by:
snow_moon earned 500 total points
ID: 17086252
SELECT DateReceived WHERE datepart(month,DateReceived) between 9 and 10
0
 
LVL 8

Expert Comment

by:doobdave
ID: 17090573
Hi there,
the above is correct and works, but you can also use the MONTH function as follows:

SELECT DateReceived WHERE MONTH(DateReceveived) = 1

which is a little more succinct.

I don't believe there's any difference in performance between the two so I guess it's just personal preference.

Best Regards,

David
0
 

Author Comment

by:IT_Steve
ID: 17091023
Thank you Snow Moon for the solution. I just had to change datepart(month,DateReceived)  to datepart("m",DateReceived)  and it performed exactly as I wanted. I did not see DoobDave's solution until after I accepted Snow Moons but can also see that would work too. Thank you both for your assistance.
0
 
LVL 8

Expert Comment

by:doobdave
ID: 17091797
Hi Steve,

no problem, glad you go your solution!

Best Regards,

David
0

Featured Post

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Well, all of us have seen the multiple EXCEL.EXE's in task manager that won't die even if you call the .close, .dispose methods. Try this method to kill any excels in memory. You can copy the kill function to create a check function and replace the …
If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…

815 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now