fzaza
asked on
create loop using vbscript/asp to update values of recordset by using values of record 1 to update values of record 2
I have an sql table with fields (id, value1, value2)
id value1 value 2
1 5 10
2 23 12
3 34 23
4 22 24
what i need is to create a vbscript of similar style to the one below which will run through a loop and for each row will proceed as follows:
1. get values of current row (which will use to update next row)
2. update values of current row with values taken from previous record
3. move to next row and get values of current row
4. update values of current row with values in step1
5. add new record in the end with last data
the resulting values of table must be after loop:
id value1 value2
1 5 10
2 5 10
3 23 12
4 34 23
5 22 24
i = 0
dim old1, old2
old2 = 100
mysql2 = "SELECT value1, value2 FROM table1"
set rstemp2 = Server.CreateObject("ADODB .Recordset ")
rstemp2.Open mysql2, conn, 1,2
do until rstemp2.eof
old1 = rstemp2.fields("value1").v alue
rstemp2.movenext
i = i + 1
loop
rstemp2.close
set rstemp2 = nothing
id value1 value 2
1 5 10
2 23 12
3 34 23
4 22 24
what i need is to create a vbscript of similar style to the one below which will run through a loop and for each row will proceed as follows:
1. get values of current row (which will use to update next row)
2. update values of current row with values taken from previous record
3. move to next row and get values of current row
4. update values of current row with values in step1
5. add new record in the end with last data
the resulting values of table must be after loop:
id value1 value2
1 5 10
2 5 10
3 23 12
4 34 23
5 22 24
i = 0
dim old1, old2
old2 = 100
mysql2 = "SELECT value1, value2 FROM table1"
set rstemp2 = Server.CreateObject("ADODB
rstemp2.Open mysql2, conn, 1,2
do until rstemp2.eof
old1 = rstemp2.fields("value1").v
rstemp2.movenext
i = i + 1
loop
rstemp2.close
set rstemp2 = nothing
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.