I'm having to insert values into a new column in our database but I can't get my head around doing this in a consistent manner. There is a lot of data so doing anything manually is pretty much out of the question. Let me set the stage:
We have a table called Occurrence and a table called OccurenceBuckets where each occurrence is reference the bucket to which it has been assigned. Previously this was a one-way reference but for various reasons we have decided to add a reference back from the OccurrenceBucket to the first Occurrence (first in time, that is). The tables now look like this:
CREATE TABLE Occurrence
OccurrenceID uniqueidentifier,
OccurrenceBucketID uniqueidentifier,
OccurrenceTime datetime,
OccurrenceMessage nvarchar
...other meta data...
CREATE TABLE OccurrenceBucket
OccurrenceBucketID uniqueidentifier,
...other meta data...
FirstOccurrenceID uniqueidentifier,
FirstOccurrenceTime datetime,
FirstOccurrenceMessage nvarchar
I'm looking for a way to determine the first occurrence belonging to a bucket and assigning the FirstOccurrenceID, FirstOccurrenceTime and FirstOccurrenceMessage with values from this first occurrence for all my occurrencebuckets.
Do any of you sql-fu experts out there have the time to help me out, all my attempts seen to produce incorrect or incomplete selection of occurrences.