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
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Kraeven
Introduction Remote Share is a simple remote sharing tool, enabling you to see, add and remove remote or local shares. The application is written in VB.NET targeting the .NET framework 2.0. The source code and the compiled programs have been in…
Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

749 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