0

I have a column call isDifFromother which is hold either 1 or 2 (default it is set to 0). when i updating a row, i want to set 2 if the isDifFromother value is having 0. if its having 1 i want to keep it as it is.

How can i check that condition inside my update query.

here is my query...,

UPDATE `customer` SET `name`='" + name + "', `isPackage`='" + packageID + "', `billing_ID`='" + biling_ID + "', `isDifFromother`=IF customer.isDifFromother = '1'  THEN '2' END IF WHERE `id`='" + cusID + "';

but its embedded with errors.

1
  • when isDifFromother=0 you want to update isDifFromother as 2 rite ? update customer set isDifFromother=2 where isDifFromother=0 Commented Mar 6, 2015 at 10:13

1 Answer 1

1

The if statement is not correct and it should be as

UPDATE `customer` SET `name`='" + name + "', `isPackage`='" + packageID + "', `billing_ID`='" + biling_ID + "', `isDifFromother`=IF(customer.isDifFromother = '0','2',customer.isDifFromother) WHERE `id`='" + cusID + "';

The following condition

`isDifFromother`=IF(customer.isDifFromother = '0','2',customer.isDifFromother)

sets isDifFromother = 2 if its 0 else remain as it is.

Sign up to request clarification or add additional context in comments.

2 Comments

Are you getting any error ? or its not updating the data ?
Have you added like isDifFromother=IF(customer.isDifFromother = '0','2',customer.isDifFromother)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.