Re: SQL NEWBEE QUESTION



"Richard Wakeman" <jrw16@xxxxxxxxxxxx> wrote in message
news:NLSdnZYrxYRGl9_YnZ2dnUVZ_tOdnZ2d@xxxxxxxxxxxxxxx
----+----*----+----*----+----*----+----*----+----*----+----*----+----*----+-
---*
[...]
What I need to have happen is to have a quick way (SQL) to go thru
the History table, and replace some data into a History Table Field
based upon whether that History records's counter part in the Main
Table has been deleted (not there anymore). We still want to keep
History Records of those deleted in the Main. Am I making any sense?

Apart from asking this in a Delphi newsgroup, yes, clear enough.


Anyway, the SQL code for it would be something like:

UPDATE HISTORY.DBF SET HDUPNUM = "1" INNER JOIN MAIN -------
and here I get lost....

You can't use an INNER JOIN, the records that _don't_ have a matching
Main record would fall out. So let's make it a LEFT JOIN. The resulting
dataset will have History records in every row, and the matching Main
row if there is one, NULLs otherwise.

You want to be able to recognise the History records that don't have
matching Main records, well, just look at any of the NULLs. If you
look at a field that can't otherwise be null, the primary key for
example, you know it's because of the entire record having gone missing.

UPDATE
History
LEFT JOIN Main
ON (History.PrimaryKey = Main.PrimaryKey)
SET
History.OrphanedFlag = 1
WHERE
(Main.PrimaryKey IS NULL);

Groetjes,
Maarten Wiltink


.



Relevant Pages

  • Re: outer Join and NULL values...?!?!!!
    ... As for your second point, I think history is on my side, so I stand by the ... "Michel Walsh" wrote: ... Values on this join" option checkbox and have the Query designer emit your ... If you want a null matching any thing: ...
    (microsoft.public.access.queries)
  • Re: Callling a function from another file...
    ... is the single most significant improvement in the history of the C ... language. ... Every time my compiler catches an error due to the ... function call not matching the prototype, ...
    (comp.lang.c)
  • Re: ot: amazons recommendation engine
    ... for rental that doesn't even come close to matching my profile ... more likely to generate income? ...
    (uk.rec.motorcycles)
  • Re: ot: amazons recommendation engine
    ... you're almost certainly right for sales - but why recommend something ... for rental that doesn't even come close to matching my profile ...
    (uk.rec.motorcycles)
  • Re: Select einer Tabelle mitteln einer zweiten Tabelle sortieren
    ... SELECT * FROM medien M inner join ... (SELECT * FROM history ... jetzt bekomme ich noch folgende Fehlermeldung: ... ORDER BY [upddate] DESC) X ON ...
    (microsoft.public.de.sqlserver)