Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Selecting specific dates - T- SQL

Posted on 2006-11-27
3
Medium Priority
?
262 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 70

Accepted Solution

by:
Scott Pletcher earned 2000 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 70

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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

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…
This video shows how to set up a shell script to accept a positional parameter when called, pass that to a SQL script, accept the output from the statement back and then manipulate it in the Shell.
Viewers will learn how to use the SELECT statement in SQL and will be exposed to the many uses the SELECT statement has.

604 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