Even though in the English language, "a date between Jan 1, 2011 and June 30, 2011" has the same meaning as "between June 30, 2011 and Jan 1, 2011", in SQL that is not the case.When you have an expression such as where o.OrderDate between GETDATE() and dateadd(month,-6,getdate())
that is equivalent towhere o.OrderDate >= GETDATE() and o.OrderDate <= dateadd(month,-6,getdate())
That would return no dates at all. So instead you should usewhere o.OrderDate between dateadd(month,-6,getdate()) and GETDATE()
which would be equivalent to where o.OrderDate >= dateadd(month,-6,getdate()) and o.OrderDate <= GETDATE()
That would pick up the six-month period.So change wherever you have "where o.OrderDate between GETDATE() and dateadd(month,-6,getdate())" to "where o.OrderDate betweendateadd(month,-6,getdate()) and GETDATE() "