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 |
|
Vack
Aged Yak Warrior
530 Posts |
Posted - 2012-02-17 : 12:19:10
|
In my table there is an ID field. what I want to do is select a record and a field from the next record. ord_no oper_no type ID 1234 10 S 10 4333 20 O 11 I would like my select statement to returnord_no oper_no NextOper type1234 10 20 S How do I modify my select statement to get what I am looking for?select ord_no, oper_no, typefrom sfdtlfil_sqlwhere type = 'S' |
|
|
X002548
Not Just a Number
15586 Posts |
|
|
Vack
Aged Yak Warrior
530 Posts |
Posted - 2012-02-17 : 12:29:52
|
| The ID increments by 1. So the record I want has an ID of 10. I want the oper_no from the record that has an ID of 11 |
 |
|
|
X002548
Not Just a Number
15586 Posts |
Posted - 2012-02-17 : 12:53:49
|
| [code]CREATE TABLE #myTable99(ord_no int, oper_no int, type char(1), ID int)GOINSERT INTO #myTable99(ord_no, oper_no, type, ID)SELECT 1234, 10, 'S', 10 UNION ALLSELECT 4333, 20, 'O', 11 UNION ALLSELECT 1234, 10, 'S', 12 UNION ALLSELECT 4333, 20, 'O', 13GO SELECT * FROM #myTable99 l LEFT JOIN #myTable99 r ON l.ID = r.ID - 1GODROP TABLE #myTable99GO[/code]Brett8-)Hint: Want your questions answered fast? Follow the direction in this linkhttp://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspxWant to help yourself?http://msdn.microsoft.com/en-us/library/ms130214.aspxhttp://weblogs.sqlteam.com/brettk/http://brettkaiser.blogspot.com/ |
 |
|
|
|
|
|
|
|