IF Statment in an UPDATE Statement - Help needed

Hello

I have been working on this problem for hours.

I would like to use an UPDATE statement with an IF .

Like this:

$unit_size is usually 1.000 but it could be less than 1.000 It is never greater than 1.000

sql_up = “UPDATE table1 SET unit_total = IF (” . $unit_size . " > .999, unit_total = unit_total + 1, unit_total = unit_total + " . $unit_size . “) WHERE unit_id != '” . $unit_id . “’ ORDER BY unit_id DESC LIMIT 64”;

It does not store any value in unit_total

Any help would be appreciated.

Thank you

So what you want is:
IF (unit_size >= 1) { unitotal++; } ELSE {unit_total += unit_size)…

why not do
$unit_size = ($unit_size >= 1) ? 1 : $unit_size;

before the query, and then just UPDATE table1 SET unit_total = unit_total + “.$unit_size.” …
?

Hello StarLion

First of all thank you for responding to my post so quickly! Many times it takes several hours or a couple of days to get a response.

Regarding your answer:
IF (unit_size >= 1) { unitotal++; } ELSE {unit_total += unit_size)

gave me a SQL Error. (Looking at it now, the brackets are not matched up correctly. I just saw that after I tried option 2.)

But I tried the second option and it worked.

Thank you