Posted by mcolson on 07/26/07 20:08
Is it possible to set a variable in a stored procedure equal to a
value from a column when that column's respective ID is equal to
max(id)-1
ID A B
1 24 24
2 53 29
3 76 47
4 32 32
What I am trying to do is update A in the last column to be equal to B
from the 4th row, plus A from the 3rd row. If I could set a variable
equal to A in row 3 (in this case 76) I could easily add the variable
to the existing value.
I've tried something like this before. I'm sure some of you will say
right away, "of coarse that doesn't work". I'm new to sql.
Set A = A + select( B from mytable where ID = (select (max(ID)-1) from
mytable))
where ID = (select (max(ID)) from mytable)
Thanks
Matt
[Back to original message]
|