SQL Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsDatabaseSQL Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old April 4th, 2005, 04:36 PM
krstofer's Avatar
krstofer krstofer is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: NJ
Posts: 60 krstofer User rank is Sergeant Major (2000 - 5000 Reputation Level)krstofer User rank is Sergeant Major (2000 - 5000 Reputation Level)krstofer User rank is Sergeant Major (2000 - 5000 Reputation Level)krstofer User rank is Sergeant Major (2000 - 5000 Reputation Level)krstofer User rank is Sergeant Major (2000 - 5000 Reputation Level)krstofer User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 12 h 50 m 52 sec
Reputation Power: 27
Send a message via AIM to krstofer
Exclamation The code to renumber does not work correctly

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

Reply With Quote
  #2  
Old April 5th, 2005, 05:07 AM
mvagh2 mvagh2 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 324 mvagh2 User rank is Corporal (100 - 500 Reputation Level)mvagh2 User rank is Corporal (100 - 500 Reputation Level)mvagh2 User rank is Corporal (100 - 500 Reputation Level)mvagh2 User rank is Corporal (100 - 500 Reputation Level) 
Time spent in forums: 2 Days 16 h 26 m 36 sec
Reputation Power: 5
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

Reply With Quote
  #3  
Old April 5th, 2005, 11:31 AM
avkb03 avkb03 is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 110 avkb03 User rank is Private First Class (20 - 50 Reputation Level)avkb03 User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 1 Day 10 h 41 m 54 sec
Reputation Power: 4
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

%>  

Reply With Quote
  #4  
Old April 12th, 2005, 11:02 AM
krstofer's Avatar
krstofer krstofer is offline
Contributing User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Mar 2004
Location: NJ
Posts: 60 krstofer User rank is Sergeant Major (2000 - 5000 Reputation Level)krstofer User rank is Sergeant Major (2000 - 5000 Reputation Level)krstofer User rank is Sergeant Major (2000 - 5000 Reputation Level)krstofer User rank is Sergeant Major (2000 - 5000 Reputation Level)krstofer User rank is Sergeant Major (2000 - 5000 Reputation Level)krstofer User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 12 h 50 m 52 sec
Reputation Power: 27
Send a message via AIM to krstofer
I will try each of these to see how they work.

I will post results.
Thanks!!

Krs

Reply With Quote
  #5  
Old April 21st, 2005, 04:55 PM
sw1 sw1 is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Apr 2005
Posts: 1 sw1 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 6 m 26 sec
Reputation Power: 0
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...

Reply With Quote
  #6  
Old April 21st, 2005, 05:03 PM
Memnoch's Avatar
Memnoch Memnoch is online now
Unholy Moderator
Click here for more information.
 
Join Date: Oct 2003
Location: In hell, where did you think?
Posts: 11,879 Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level)Memnoch User rank is Lieutenant Colonel (40000 - 50000 Reputation Level) 
Time spent in forums: 3 Weeks 5 Days 18 h 10 m 33 sec
Reputation Power: 500
Quote:
Originally Posted by krstofer
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.

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.

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > The code to renumber does not work correctly


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump



 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT