Question

I'm using Microsoft SQL Server 2000 (version 8); I would like to query and return all records for a given month.

I would provide the month and year and would get every record with a date falling within that period.

I'm hoping there is a way that is more elegant than what I've seen on google with looping through days or determining last day.

Was it helpful?

Solution

This is the simplest way but not performance efficient. as this query will not make use of any indexes defined on the DateColumn.

SELECT *
FROM Table_Name
WHERE MONTH(DateColumn) = 12    --<-- Month December
AND   YEAR(DateColumn)  = 2013  --<-- Year 2013

A better approach will be something like ...

For example if you want all the records in JUNE 2013 you could do something like .....

SELECT *
FROM DateColumn >= '20130601'
AND  DateColumn <= '20130630'

OTHER TIPS

From within Microsoft Query I use: docdate

=#1/09/2022# And <=#30/09/2022#

I'm still trying to find a more elegant way just to refer to all of the month before current.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top