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
188 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
Comment Utility
SELECT DateReceived WHERE datepart(month,DateReceived) between 9 and 10
0
 
LVL 8

Expert Comment

by:doobdave
Comment Utility
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
Comment Utility
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
Comment Utility
Hi Steve,

no problem, glad you go your solution!

Best Regards,

David
0

Featured Post

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

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…
Introduction When many people think of the WebBrowser (http://msdn.microsoft.com/en-us/library/2te2y1x6%28v=VS.85%29.aspx) control, they immediately think of a control which allows the viewing and navigation of web pages. While this is true, it's a…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

772 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

11 Experts available now in Live!

Get 1:1 Help Now