|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
This is the code I have:
Code:
DIM indexNum
DIM strSQL
DIM newStrSQL
DIM rs1
dim i
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open MM_RU_STRING
strSql = "SELECT id FROM students"
Set rs = Conn.Execute(strSql)
i = 1
Do until rs.eof
Conn.Execute("UPDATE Students Set id = " & i & " WHERE id = " & rs("id"))
rs.movenext
i = i + 1
loop
%>
The problem with this code is, if bases the next record off of the previous record. So if I have a bunch of records where the ID is "1" then they will all stay as one. I need to renumber all my records, about 1300. If anyone can help, please do, I will not be able to go home until I get this done. Right now, now one will be able to use the website. Thank You, Krstofer |
|
#2
|
|||
|
|||
|
Hi,
Why not loop through the entire set and change it yourself? Code:
i = 1
Do Until rs.eof
rs.Edit
rs("id") = i
rs.Update
rs.MoveNext
i = i + 1
Loop
Provided of course you are able to change the ID (no Autonumber) but looking at your question I think it's editable. Regards, Michiel |
|
#3
|
|||
|
|||
|
I'm guessing you're having an issue because of duplicates when trying to renumber.
Try renumbering first to something like 10001, 10002, etc... Then reloop and number from 1 to whatever... Code:
DIM indexNum
DIM strSQL
DIM newStrSQL
DIM rs1
dim i
Dim arrStudentID
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open MM_RU_STRING
strSql = "SELECT id FROM students"
Set rs = Conn.Execute(strSql)
arrStudentID = rs.GetRows()
rs.Close
'Renumber to 10001, 10002, etc...
for i = 0 to UBound(arrStudentID)
Conn.Execute "UPDATE Students Set id = " & i + 10001 & " WHERE id = " & arrStudentID(i)
next
'Renumber back to 1, 2, etc...
Set arrStudentID = nothing
Dim arrStudentID
Set rs = Conn.Execute(strSql)
arrStudentID = rs.GetRows()
for i = 0 to UBound(arrStudentID)
Conn.Execute "UPDATE Students Set id = " & arrStudentID(i) - 10000 & " WHERE id = " & arrStudentID(i)
next
%>
|
|
#4
|
||||
|
||||
|
I will try each of these to see how they work.
I will post results. Thanks!! Krs |
|
#5
|
|||
|
|||
|
SQL alternative
declare @intCounter int
set @intCounter = 0 update Students Set SET @intCounter = id = @intCounter + 1 I know it is not ASP code, but it will get the job done... |
|
#6
|
||||
|
||||
|
Quote:
So what you are saying it you have a bunch of duplicated ID numbers? Is ID the primary key? If you don't have a unique field, then trying to update records is going to be a problem. |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > The code to renumber does not work correctly |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|