sql >> Database >  >> RDS >> Mysql

MySQL-updatekolom alleen als waarde niet leeg is waar

Probeer het met Coalesce .

   $query = " UPDATE user 
   SET 
 `Title`       = CASE WHEN `Title`='' or `Title` IS NULL THEN '$title' END, 
 `Description` = CASE WHEN `Description`='' Or `Description` IS NULL THEN '$description' END, 
  `Date`       = CASE WHEN `Date`='' Or Date` IS NULL THEN '$date' END
    WHERE `id` = '".$id."' ";

of :

  $query = " UPDATE user 
  SET 
 `id`         = Coalesce('$id''".$id."' , NULLIF(`id`,'')), 
`Title`       = Coalesce('$title''".$title."',NULLIF(`Title`,'') ) , 
`Description` = Coalesce('$description''".$description."' , NULLIF(`Description`,'') ) , 
 `Date`       = Coalesce('$date''".$date."',NULLIF(`Date`,'')) 
 WHERE `id` = '$id''".$id."' ";


  1. PostgreSQL:FATAL - Peer-authenticatie mislukt voor gebruiker (PG::ConnectionBad)

  2. Entity Framework Code First met SQL Server-synoniemen

  3. SQL Server 2008 Rij Tijdstempels invoegen en bijwerken

  4. Auto_increment-waarden in InnoDB?