Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
NTC
Starting Member
21 Posts |
Posted - 2008-04-07 : 22:36:01
|
Is Access/Jet Table is this:id, wo, 1, 2345-1 2, 2345-1 3, 2345-14, 5432-15, 5432-16, 5432-1Need result:id, wo, parent1, 2345-1, 12, 2345-1, 13, 2345-1, 24, 5432-1, 45, 5432-1, 46, 5432-1, 5the logic is If wo = wo of ID-1 then Parent = Id-1If wo not= wo of ID-1 then Parent = Idcould use help on the correct sql statement for this...thanks in advance... |
|
jhocutt
Constraint Violating Yak Guru
385 Posts |
Posted - 2008-04-07 : 23:04:37
|
[code]SELECT t.id, t.wo, IIF(isnull(t2.id), t.id, IIF(t.wo = t2.wo, t2.id, t.id) ) as parent FROM t left join t t2 ON t.id-1=t2.id;[/code]"God does not play dice" -- Albert Einstein"Not only does God play dice, but he sometimes throws them where they cannot be seen." -- Stephen Hawking |
 |
|
NTC
Starting Member
21 Posts |
Posted - 2008-04-08 : 15:02:34
|
Much Thanks - works like a champ.. !! |
 |
|
|
|
|
|
|