month summary query (with datepart) ignoring first month in each year?

i am using this query to summarize order data by month...
select  datepart(mm,[MAILDATE]) as monthnum,
         min([MAILDATE]) as [Month Commencing]
         , count(*) as #Orders
from ORDERHEADER
where
     FULLORDERNO not like 'W%' and STATUS in ( 'PC','PR') and ENTRYOPER <> 'WEBMACS' and COMPANY = '01' and
     Datepart(mm,[MAILDATE]) <> Datepart(mm,getdate())
group by DatePart(yy,[MAILDATE]),Datepart(mm,[MAILDATE])
order by [Month Commencing]


a snippet of the output looks like this:
monthnum      Month Commencing      #Orders
10      20061001                          18595
11      20061101                          14604
12      20061201                          13621
2      20070201                          14054
3      20070301                           20595

it skipped month 1 of 2007  --- ie, month commencing 20070101

what have i missed in the query to get january to show up?
jimwarrenusAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

sdstuberCommented:
Datepart(mm,[MAILDATE]) <> Datepart(mm,getdate())  


you're explicitly skipping data that is for the current month
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Ashish PatelCommented:
Why you are adding the condition to neglect the current month by using this in where clause
and     Datepart(mm,[MAILDATE]) <> Datepart(mm,getdate())

Rahter just use this.
select  datepart(mm,[MAILDATE]) as monthnum,
         min([MAILDATE]) as [Month Commencing]
         , count(*) as #Orders
from ORDERHEADER
where
     FULLORDERNO not like 'W%' and STATUS in ( 'PC','PR') and ENTRYOPER <> 'WEBMACS' and COMPANY = '01' 
group by DatePart(yy,[MAILDATE]),Datepart(mm,[MAILDATE])
order by [Month Commencing]

Open in new window

0
jimwarrenusAuthor Commented:
Got it.....thanks!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.