Re: Question on SQL query ?

From: <champs_at_cnb07v.hhcs.gov.au>
Date: 9 Nov 93 09:42:12 +1000
Message-ID: <1993Nov9.094212.1_at_cnb07v.hhcs.gov.au>


In article <CG6Mzz.31sB_at_austin.ibm.com>, rrairao_at_austin.ibm.com writes:
> Hi Sql users :
>
> I have a question for writing a Sql query.
>
> I have a table with several fields including a date field :
>
> e.g. Table1
> fld1 fld2 .... .... ..... code dateo
> [data] .... ... .. 10 01-mar-93
> ... 60 10-oct-93 and soon
>
> I have created a similar table ( tablehist ) with same fields to keep an
> archive.
>
> I would like to grab the records from table1 between sysdate ( today )
> and 3-months old ( from today ) based on dateo field in table1 and
> based on code = 'xx' and insert those records in tablehist data.
>
> The sql code should run on any given day.
>
> Any ideas and help would be appreciated. Please post on this group.
>
> Thanks.
> Raj
>

This should do what you need:

	INSERT INTO tablehist
	SELECT *
	FROM   table1
	WHERE  code = 'xx'
	AND    dateo between sysdate and ADD_MONTHS(sysdate,-3);
  
-----------------------------------------------------------------------------
    /\       Steven Champness (champs_at_cnb07v.hhcs.gov.au)
   /  \      Dept of Health, Housing, Local Govt and Community Services
  /    \     Brisbane, Queensland via Canberra, Australia
 /      \    

/ / \ The opinions expressed above were forcibly implanted in my head \ / / / by aliens from Alpha Zeltex 4, during a recent Invasion attempt.  \/ / / /
  \/ / /     MACINTOSH      : If you need a manual to operate it, it wasn't
   \/ /      SOFTWARE AXIOM : designed properly in the first place !!!!
    \/ Received on Tue Nov 09 1993 - 00:42:12 CET

Original text of this message