?
Solved

Selecting specific dates - T- SQL

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

Free Backup Tool for VMware and Hyper-V

Restore full virtual machine or individual guest files from 19 common file systems directly from the backup file. Schedule VM backups with PowerShell scripts. Set desired time, lean back and let the script to notify you via email upon completion.  

Question has a verified solution.

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

Why is this different from all of the other step by step guides?  Because I make a living as a DBA and not as a writer and I lived through this experience. Defining the name: When I talk to people they say different names on this subject stuff l…
In this article we will learn how to fix  “Cannot install SQL Server 2014 Service Pack 2: Unable to install windows installer msi file” error ?
Using examples as well as descriptions, and references to Books Online, show the documentation available for date manipulation functions and by using a select few of these functions, show how date based data can be manipulated with these functions.
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.
Suggested Courses

801 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