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
195 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

Enroll in June's Course of the Month

June's Course of the Month is now available! Every 10 seconds, a consumer gets hit with ransomware. Refresh your knowledge of ransomware best practices by enrolling in this month's complimentary course for Premium Members, Team Accounts, and Qualified Experts.

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…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

728 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