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 > ANSI SQL > what's the best way to update multiple fields

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 06-24-02, 10:12
rimian rimian is offline
Registered User
 
Join Date: May 2002
Location: Australia
Posts: 26
what's the best way to update multiple fields

Hello!

I want to do this [in access]:

UPDATE table SET field1 = "this" WHERE field2 = "that" AND SET field1 = "thisotherthing" WHERE field2 = "thatotherthing"

Before i was creating loops and opening and closing the connection all the time but it seems like a clumsy method.

Regards
RIM

thanks in advance!
__________________
Web Developer
Reply With Quote
  #2 (permalink)  
Old 06-25-02, 16:21
alligatorsql.com alligatorsql.com is offline
Registered User
 
Join Date: Jul 2001
Location: Germany
Posts: 189
Hello,

use

UPDATE table SET field1 = DECODE(field2, 'that', 'this', 'thatotherthing', 'thisotherthing');

Hope that helps ?

Regards
Manfred Peter
(Alligator Company(
http://www.alligatorsql.com
Reply With Quote
  #3 (permalink)  
Old 06-25-02, 16:30
alligatorsql.com alligatorsql.com is offline
Registered User
 
Join Date: Jul 2001
Location: Germany
Posts: 189
Hello,

oh sorry ... I didnīt read that little word access. DECODE is for Oracle but perhaps you will find the same command in access ???

Sorry again

Manfred Peter
(Alligator Company)
http://www.alligatorsql.com
Reply With Quote
  #4 (permalink)  
Old 06-26-02, 13:56
jaydog96 jaydog96 is offline
Registered User
 
Join Date: Feb 2002
Location: North Carolina
Posts: 13
In the QBE grid, you can do the following:

Set up an UPDATE query. Select field1 as the field to be updated. In the Criteria box, enter the following formula:

IIf([field2] = "that","this","thatotherthing")

If you need to test field2 for more than one value, use a nested IIf (see the Help file for assistance).

If you want to do this in code, open a recordset based on the table. Assign field1 and field2 to variables, then use a SELECT CASE statement to test the value of field2 and update field1 accordingly.

Hope it helps,

j-Dog
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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On