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 February 3rd, 2005, 12:32 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
Trying to update index for each field...

Hello,

I have a DB that has a lot of double users and junk users. I want to delete
the extras and renumber the index. I was trying to use a for each loop and movenext()
but I don't know how to use them correctly in an update.

The table name is student, and the field I want to update is ID.


if anyone can help, I would really appreciate it.

Thanks,
Krs

Reply With Quote
  #2  
Old February 3rd, 2005, 01:40 PM
Memnoch's Avatar
Memnoch Memnoch is offline
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
What database are you using?
What's the data type of the ID field in the database?

Reply With Quote
  #3  
Old February 3rd, 2005, 02:06 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
The database is SQL and the type is 'int'.

I've tried so many different versions of code, but here is one.

Code:
 
strSQL= "select id from students"
newStrSQL= "update students SET id ='" & indexNum & "'"
	SET rs1 = Server.CreateObject("ADODB.Connection")
	rs1.Open = MM_RU_STRING
rs1.Execute (strSQL)
 
while not rs1.eof 
indexNum = indexNum + 1
 
	rs1.Execute (newStrSQL)
 
rs1.movenext()
wend 
 


I fogot ot include the error I get.
|21|800a0bb9|Arguments_are_of_the_wrong_type__are_ out_of_acceptable_range__or_are_in_conflict_with_o ne_another.

Reply With Quote
  #4  
Old February 3rd, 2005, 02:37 PM
Memnoch's Avatar
Memnoch Memnoch is offline
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
1) SQL isn't a database, it's a language and it stands for (Structured Query Language).
SQL Server is a database.

2) Your code is wrong for a couple of reasons

A) strings (varchar, etc...) are the only types the need to be surrounded by single quotes (')
So this code
Code:
newStrSQL= "update students SET id ='" & indexNum & "'"

Should be like this, since id is an int (number) type and not a string.
Code:
newStrSQL= "UPDATE students Set id = " & indexNum 


This is how I would do it
Code:
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

Reply With Quote
  #5  
Old February 3rd, 2005, 02:58 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
Quote:
Originally Posted by Memnoch
1) SQL isn't a database, it's a language and it stands for (Structured Query Language).
SQL Server is a database.


Thanks, I know the difference, I just knew you would know what I meant. :-)

Quote:
Originally Posted by Memnoch
2) Your code is wrong for a couple of reasons

A) strings (varchar, etc...) are the only types the need to be surrounded by single quotes (')
So this code
Code:
newStrSQL= "update students SET id ='" & indexNum & "'"

Should be like this, since id is an int (number) type and not a string.
Code:
newStrSQL= "UPDATE students Set id = " & indexNum 




Ok, so since the indexNum was a variable, I didn't need the extra singe quote mark? I was never sure as to why I needed to use the single quote. was that the main problem?



This is how I would do it
Code:
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

[/QUOTE]


Thanks it works great. You're the best!!

Reply With Quote
  #6  
Old February 3rd, 2005, 03:04 PM
Memnoch's Avatar
Memnoch Memnoch is offline
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
Review my signature regarding "Helpful Posts".

Reply With Quote
Reply

Viewing: ASP Free ForumsDatabaseSQL Development > Trying to update index for each field...


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