php - MySQL Error 1064 when using CASE trying to update a field in between two tables -


i have 2 tables: projects , temp_projects ($table in code below). i'm using following mysql query try , update field on temp_projects using data projects.

here query:

    $this->q("update $table, projects      case         when $table.$number_field != projects.number              set $table.$id_field = projects.id $table.old_proj_num = projects.number         when $table.$number_field = projects.number             set $table.$id_field = projects.id $table.$number_field = projects.number      end"); 

the error is:

mysql error 1064: have error in sql syntax; check manual corresponds mysql server version right syntax use near 'case                     when temp_projects.number != projects.number                             set temp_proj' @ line 2 when executing: update temp_projects, projects              case                     when temp_projects.number != projects.number                             set temp_projects.project_id = projects.id temp_projects.old_proj_num = projects.number                     when temp_projects.number = projects.number                             set temp_projects.project_id = projects.id temp_projects.number = projects.number              end 

the issues i'm having line in error message "then set temp_proj' @ line 2

after should read then set temp_projects.project_id = projects.id temp_projects.number = projects.number.

i'm trying figure out why it's cutting off query after then set temp_proj

i'm not familiar using case command pointers appreciated.

thanks.

make query below:

> update students     set name =  case   >                         when name = 'abc' 'mno'  >                         when name = 'def' 'jkl'  >                         when name = 'efg' 'ghi'  >                         else name >      end    lastname in ('abc', 'def', 'efg') 

Comments

Popular posts from this blog

angular - Is it possible to get native element for formControl? -

unity3d - Rotate an object to face an opposite direction -

javascript - Why jQuery Select box change event is now working? -