Re: Last Full Three Months?

From: mountain man <hobbit_at_southern_seaweed.com.op>
Date: Thu, 02 Jun 2005 09:17:33 GMT
Message-ID: <N8Ane.479$F7.444_at_news-server.bigpond.net.au>


"Dan" <dan_at_nospam.com> wrote in message news:fwkne.15$4A3.2097_at_news.uswest.net...
> Hi,
>
> I have sales line item detail like
>
> invoicedate, custid, ordernum
>
> Is there a way using SQL to only return records for the last full three
> months? For example, if today is 2/4/05, I would want records with
> invoicedate between 11/1/04 and 1/31/05.

Try this:

select invoicedate
from sometable
where invoicedate between

      dateadd(mm,-3,cast(convert(varchar(8),getdate(),111)+'01' as datetime))

      and
      dateadd(dd,-1,cast(convert(varchar(8),getdate(),111)+'01' as 
datetime))
-- 
Pete Brown
IT Managers & Engineers
Falls Creek
Australia
www.mountainman.com.au/software
Received on Thu Jun 02 2005 - 11:17:33 CEST

Original text of this message