declare @sql varchar(100); set @sql = 'update user set '; if(PUserName is not null) then @sql = concat(@sql, 'username = "test"'); end if; if(PReMark is not null) then @sql = concat(@sql, ',Re = 'TestRe''); end if; @sql = concat(@sql, ' where userid = 1'); prepare s from @sql; execute s; deallocate prepare s;
set @sql = 'update user set ';
if(PUserName is not null) then
@sql = concat(@sql, 'username = "test"');
end if;
if(PReMark is not null) then
@sql = concat(@sql, ',Re = 'TestRe'');
end if;
@sql = concat(@sql, ' where userid = 1');
prepare s from @sql;
execute s;
deallocate prepare s;