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 |
|
Charlow80
Starting Member
9 Posts |
Posted - 2009-11-16 : 22:19:49
|
| I want to subtract the value end from the first record with id 1 from the start value of the id = 2 and continue with the values from odd ids minus the even ones. Also, either update or insert the values into the diff column. Does anyone know how to do this, I am not sure if I use a cursor or it t-sql has another way of subtracting these values in different records.Below are my first 4 recordsid tid Lid start end diff1 302297 794 100 885 02 302297 798 885 1295 03 386050 747 63690 64236 04 386050 750 64237 64786 0 |
|
|
khtan
In (Som, Ni, Yak)
17689 Posts |
Posted - 2009-11-16 : 22:52:02
|
[code]select *, diff = t2.start - t1.end from tbl t1 inner join tbl t2 on t1.id = t2.id - 1[/code] KH[spoiler]Time is always against us[/spoiler] |
 |
|
|
Charlow80
Starting Member
9 Posts |
Posted - 2009-11-17 : 01:10:00
|
| Thanks, thats what I needed! |
 |
|
|
|
|
|