|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
Stop making mediocre tutorials.The best tutorials are video! Camtasia Studio makes it easy to create engaging, buzz-building screen videos at any size, in any popular format. Download the free trial!
|
|
#1
|
|||
|
|||
|
Can SQL lookup a value in the previous record?
Hi,
I am a newbie to DB2 SQL and need to know if it is possible with DB2 SQL to insert the value of the same field in the previous record in the field in the current record if another field is not empty? Basically my question is if it possible for SQL to lookup the value in the previous record? The previous record is the physical record just before the current record, there is not necessary a relationship between both records. Thanks. |
|
#2
|
|||
|
|||
|
Ehhh?
Quote:
So your saying... record1 field1=x record2 field1=y field2=NULL insert the value of record1.field1 into record2.field1 where record2.field1 AND record2.field = NULL Is that what your tryign to say? |
|
#3
|
||||
|
||||
|
You need a trigger. Look at the SQL Reference on create trigger using the INSERT flag. This will likely require a auto-increment field so you can select max to get the last record.
|
|
#4
|
|||
|
|||
|
It depends - tell us more about the DB structure and exactly what you are trying to accomplish in more detail.
Thinking this deals with rows in the same table and probably not an identity column? fv
__________________
...because that is the way we have always done it. We've been doing it like that for 80 Years! (How do we change that mindset?) |
![]() |
| Viewing: Dev Shed Forums > Databases > DB2 Development > Can SQL lookup a value in the previous record? |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|