If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ASP > Updating multiple records with conditions

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 11-10-06, 18:39
davidevan davidevan is offline
Registered User
 
Join Date: Jun 2006
Posts: 11
Updating multiple records with conditions

I'm trying to update a single field in a table according to the an age category as a condition.

The meat of the code that executes looks like this (I created a record set, and loop through it until there are no records):

Code:
Do While Not rstRecSet.EOF 
  
    ' gets the difference between todays date and db player date
    intDifference = DateDiff("yyyy", CDate(rstRecSet("BIRTHDATE")), Date)
    
    If intDifference <= 8 Then
    	SQLUpdate = "UPDATE Player SET DIVISION = 'LEARN TO PLAY';"
    ElseIf intDifference <= 10 Then
	SQLUpdate = "UPDATE Player SET DIVISION = 'MITES';"
    etc.....
    End If

   ' execute my sql statement here to update record
   oC.execute(SQLUpdate)
	
   ' move to next record to update....
    rstRecSet.MoveNext
    	
Loop
I did a response.write for the different in age and it shows the difference between ages for all entries in the database (good), but it will only update the first entry and set every single entry in the database according to the first entry (so if the age difference is 17, it will set the division properly, but every single record is going to have that division name, regardless of their age category from the first to last record).

Am I out to lunch here, on the right track? Is there possibly a better way of doing this that I'm unaware of? An SQL update statement with conditions?
Any sort of help would be appreciated.
Reply With Quote
  #2 (permalink)  
Old 11-11-06, 00:27
davidevan davidevan is offline
Registered User
 
Join Date: Jun 2006
Posts: 11
Ok, figured out the problem. Sat down and thought about it, turns out I needed a WHERE clause in those updates. It would always take the last value in the record and whatever the criteria was, all values would be based on it, makes sense now. All working good with the WHERE clause.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On