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 > Database Server Software > MySQL > help with update query logic

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 09-07-07, 19:01
rguy84 rguy84 is offline
Registered User
 
Join Date: Jun 2004
Location: Seattle, WA
Posts: 601
help with update query logic

My form is to update a record, and it has two combo boxes. These you are able to select a program and a item associated with that program, like a task associated with that program. for example, a car manufacturer then a model. I have three text area boxes with details. Since I don't have a handle on ajax yet, the boxes have a place holder value of "Type a new blah or just delete this" where blah is a change to that field, so the old value isn't totally important. Each blah is diffent, so just change blah to another word for the other two text areas.

I need help with putting a query together that looks at each text area and if it isn't that specified value, update that record. I am thinking something like:

Code:
UPDATE myTable
   CASE
     WHEN (($textarea1 !== "Type a new blah or just delete this") OR ($textarea1 !== NULL)
       THEN SET myField = $textarea1 
   END CASE
   CASE
     WHEN (($textarea2 !== "Type a new blah2 or just delete this") OR ($textarea1 !== NULL)
       THEN SET myField2 = $textarea12
   END CASE
   CASE
     WHEN (($textarea3 !== "Type a new blah3 or just delete this") OR ($textarea1 !== NULL)
       THEN SET myField3 = $textarea3 
   END CASE
   WHERE someField1 = $myCombo1 AND someField2 = $myCombo2;
__________________
Ryan
My Blog
Reply With Quote
  #2 (permalink)  
Old 09-07-07, 19:41
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
Code:
UPDATE myTable 
   SET myField = $textarea1 
 WHERE someField1 = $myCombo1 
   AND someField2 = $myCombo2
   AND $textarea1 <> 'Type a new blah or just delete this"'
;
UPDATE myTable 
   SET myField = $textarea2 
 WHERE someField1 = $myCombo1 
   AND someField2 = $myCombo2
   AND $textarea2 <> 'Type a new blah or just delete this"'
;
UPDATE myTable 
   SET myField = $textarea3 
 WHERE someField1 = $myCombo1 
   AND someField2 = $myCombo2
   AND $textarea3 <> 'Type a new blah or just delete this"'
;
of course, this doesn't make much sense -- why would you hvae three different form textareas all updating the same column on the same row

but those were your specs

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #3 (permalink)  
Old 09-07-07, 19:53
rguy84 rguy84 is offline
Registered User
 
Join Date: Jun 2004
Location: Seattle, WA
Posts: 601
Rudy, Each textarea isn't updating the same column on the same row (myField1, myField2, myField3). Each textarea is updating a different column in the same row.
Think of the two combos as fixed points. The text areas can be changed. I could just use one combo, but the second gives more security.

Thanks.
__________________
Ryan
My Blog
Reply With Quote
  #4 (permalink)  
Old 09-07-07, 20:47
r937 r937 is offline
SQL Consultant
 
Join Date: Apr 2002
Location: Toronto, Canada
Posts: 19,534
ah, i see

okay, adjust my code so that each textarea updates the correct field

thanks

__________________
r937.com | rudy.ca
please visit Simply SQL and buy my book
Reply With Quote
  #5 (permalink)  
Old 09-08-07, 04:48
rguy84 rguy84 is offline
Registered User
 
Join Date: Jun 2004
Location: Seattle, WA
Posts: 601
well of course. That is one narly statement.
__________________
Ryan
My Blog
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