MySQL conditional field update

Posted on 2006-05-11
Last Modified: 2008-01-16
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 with the MySQL Connector and a parameter for passing the data.

Question by:minotaur01
    LVL 22

    Accepted Solution

    This ought to work.

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

    CONCAT() returns NULL if any argument is NULL.

    Author Comment

    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

    Top 6 Sources for Identifying Threat Actor TTPs

    Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

    Join & Write a Comment

    This guide whil teach how to setup live replication (database mirroring) on 2 servers for backup or other purposes. In our example situation we have this network schema (see atachment). We need to replicate EVERY executed SQL query on server 1 to…
    Does the idea of dealing with bits scare or confuse you? Does it seem like a waste of time in an age where we all have terabytes of storage? If so, you're missing out on one of the core tools in every professional programmer's toolbox. Learn how to …
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    746 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    15 Experts available now in Live!

    Get 1:1 Help Now