Deleting data from one table, where the date is older than a temp table

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • SCDSC

    Deleting data from one table, where the date is older than a temp table

    Hi,

    I need to delete all data in a table where the date is older than that in a temp table.

    Basically i have tblTrends and tbltempTrends. I only want new data in tblTrends as currently the data (imported weekly) into tbltempTrends just appends to tblTrends via a DTS package ran weekly.

    Thanks!!
  • NeoPa
    Recognized Expert Moderator MVP
    • Oct 2006
    • 32661

    #2
    You probably need something like (you don't share field names so I'll guess) :
    Code:
    DELETE FROM [tblTrends]
    FROM        [tblTrends] AS tT
                INNER JOIN
                [tblTempTrends] AS tTT
      ON        (tT.TrendID = tTT.TrendID)
     AND        (tT.Date < tTT.Date)
    Your question also fails to say which records to even compare for dates, so I've assumed an ID field. Obviously you need to take the concept of the SQL and change it to match your own circumstances.

    Comment

    Working...