[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1382
  • Last Modified:

MySQL conditional field update

I trying to create an update statement that update a single field in two different ways.

Here is what i have so far:
UPDATE service_surveys SET notes = IF(notes IS NULL, CONCAT(notes, ?nts), CONCAT(notes, '\n', ?nts)) WHERE id =  {An ID}

The statement executes without throwing any errors but the field dose't update. Basically i trying to add string data to the existing string data and add a newline between the two strings only if there is already a string data present.

I'm using ASP.net with the MySQL Connector and a parameter for passing the data.

1 Solution
This ought to work.

UPDATE service_surveys SET notes = IF(notes IS NULL, ?nts, CONCAT(notes, '\n', ?nts)) WHERE id =  {An ID}

From http://dev.mysql.com/doc/refman/5.0/en/string-functions.html:
CONCAT() returns NULL if any argument is NULL.
minotaur01Author Commented:
Thanks, that fixed the problem i total wasn't thinking when i put in the CONCAT for the 'true' condition, it didn't need to concat there is nothing the.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now