Solved

Selecting specific dates - T- SQL

Posted on 2006-11-27
3
252 Views
Last Modified: 2012-08-14
i need a query that will let me select distinct months, from a column that contains the date in the format: 10/20/2006 12:00:00 AM



0
Comment
Question by:sammaell
[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
3 Comments
 
LVL 69

Accepted Solution

by:
Scott Pletcher earned 500 total points
ID: 18021982
You can use:

SELECT MONTH(date), YEAR(date)
WHERE MONTH(date) = 10
AND YEAR(date) = 2006
0
 
LVL 20

Expert Comment

by:Sirees
ID: 18021994
You can use Month function

from BOL

MONTH
Returns an integer that represents the month part of a specified date.

Syntax
MONTH ( date )
0
 
LVL 69

Expert Comment

by:Scott Pletcher
ID: 18021995
However, it's better to use a date range expression that SQL can use to search an index (if one exists now or in the future):

SELECT ...
FROM ...
WHERE date >= '20061001' AND date < '20061101'  --to get Oct 2006 only
0

Featured Post

The Ultimate Checklist to Optimize Your Website

Websites are getting bigger and complicated by the day. Video, images, custom fonts are all great for showcasing your product/service. But the price to pay in terms of reduced page load times and ultimately, decreased sales, can lead to some difficult decisions about what to cut.

Question has a verified solution.

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

In the first part of this tutorial we will cover the prerequisites for installing SQL Server vNext on Linux.
Recently we ran in to an issue while running some SQL jobs where we were trying to process the cubes.  We got an error saying failure stating 'NT SERVICE\SQLSERVERAGENT does not have access to Analysis Services. So this is a way to automate that wit…
Familiarize people with the process of utilizing SQL Server functions from within Microsoft Access. Microsoft Access is a very powerful client/server development tool. One of the SQL Server objects that you can interact with from within Microsoft Ac…
Using examples as well as descriptions, and references to Books Online, show the different Recovery Models available in SQL Server and explain, as well as show how full, differential and transaction log backups are performed

726 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