Solved

Selecting specific dates - T- SQL

Posted on 2006-11-27
3
211 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
  • 2
3 Comments
 
LVL 69

Accepted Solution

by:
ScottPletcher 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:ScottPletcher
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

Better Security Awareness With Threat Intelligence

See how one of the leading financial services organizations uses Recorded Future as part of a holistic threat intelligence program to promote security awareness and proactively and efficiently identify threats.

Join & Write a Comment

This article explains how to reset the password of the sa account on a Microsoft SQL Server.  The steps in this article work in SQL 2005, 2008, 2008 R2, 2012, 2014 and 2016.
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the SELECT statement in SQL to return specific rows and columns, with various degrees of sorting and limits in place.

705 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

19 Experts available now in Live!

Get 1:1 Help Now