Bit of a strange question. Entries in my table have three relevant columns:
drug
date_1
date_2
seq_id
I am trying to make it such that every drug with the lowest seq_id
has a date_2
equal to the date_1
of the drug with the second lowest seq_id
(the second lowest will always be lowest + 1) with the same drug name.
Does this make sense?
I don't have any real clue how to go about doing this. I've managed to make a query that returns the date_1
and seq_id
of every second-lowest record, and now I want to make it such that every row with a seq_id
exactly one lower than any seq_id
in this set of records has date_2
= date_1
of the record with the 1-higher seq-id
.
God this is really confusing, I hope it comes through.
Best Answer
The SQLServer version of this could look like this.
First we want the drug table and some values
Then we need to update the next lowest seq_id with a date
And the update the lowest date_2 value with the date_1 value from the second lowest seq_id - This is update with a join with the strange looking SQL-Server syntax and is
And Clean up