Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 how to get results from specific month in SQL 2005

Author  Topic 

Josh_Pacey
Starting Member

2 Posts

Posted - 2008-12-01 : 13:52:12
Hi im new to SQL and struggling with a query, was wondering if anyone could help;
Im trying to run a query to get results of a certain month within a table I think this is what it would look like but it doesn't seem to work
thanks

select *
from customerOrder
where date (mm.(10))

webfred
Master Smack Fu Yak Hacker

8781 Posts

Posted - 2008-12-01 : 15:03:07
An example:

select * from customerOrder
where MONTH(YourDateColumn) = 10 -- 10=october

But this is regardless the year.
You can use YEAR() similar to limit the result.

Webfred


No, you're never too old to Yak'n'Roll if you're too young to die.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-02 : 00:41:33
if your date column has an existing index,
DECLARE @Y int,@M int
SELECT @Y=2008,@M=10--example values

select * from customerOrder
where YourDateColumn> = DATEADD(mm,@M-1,DATEADD(yy,@Y-1900,0))
AND YourDateColumn<DATEADD(mm,@M,DATEADD(yy,@Y-1900,0))
Go to Top of Page

Josh_Pacey
Starting Member

2 Posts

Posted - 2008-12-03 : 06:14:45
hey this worked great thanks for all your help
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-12-03 : 06:33:12
cheers
Go to Top of Page
   

- Advertisement -