UPDATE using a join and NOT EXISTS?
From: Paul (paulhodgson24_at_hotmail.com)
Date: 07/07/04
- Next message: A.M: "Re: SQL Profiler doesn't filter"
- Previous message: Jacco Schalkwijk: "Re: Create date from date parts"
- Next in thread: Anith Sen: "Re: UPDATE using a join and NOT EXISTS?"
- Reply: Anith Sen: "Re: UPDATE using a join and NOT EXISTS?"
- Reply: Anith Sen: "Re: UPDATE using a join and NOT EXISTS?"
- Messages sorted by: [ date ] [ thread ]
Date: 7 Jul 2004 06:12:29 -0700
Hi all,
I have two tables in a database, one of which I'm trying to update
based on the (non) existence of data in the other. Table one is a
staging table containing "real-time" data for a "To-Do" task list,
where data is inserted, updated and deleted frequently. Table two
contains identical data for reporting, except that it is a historical
version of the first table, and also contains an additional field to
flag whether or not the task is complete. When a task is complete, it
is deleted from the first table, but not from the second - what I need
to do, is update the second table to flag that particular task as
complete. I've tried a couple of different methods, but can't seem to
get it right! I assumed I could just use a relatively simple UPDATE
statement, containing a NOT EXISTS clause as follows:
UPDATE Table2
SET TaskComplete = 1
WHERE
NOT EXISTS (
SELECT *
FROM Table2 AS t2 INNER JOIN table1 AS t1
ON t2.Task_ID = t1.Task_ID
)
I'm relatively new to the more complex aspects of T-SQL, so it's
probably no surprise to you that this doesn't work! I'm a bit lost on
this one, so any push in the right direction would be gratefully
received!
Thanks for any help,
Paul.
- Next message: A.M: "Re: SQL Profiler doesn't filter"
- Previous message: Jacco Schalkwijk: "Re: Create date from date parts"
- Next in thread: Anith Sen: "Re: UPDATE using a join and NOT EXISTS?"
- Reply: Anith Sen: "Re: UPDATE using a join and NOT EXISTS?"
- Reply: Anith Sen: "Re: UPDATE using a join and NOT EXISTS?"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|