On 10/28/2013 2:06 PM, Neil Tompkins wrote:
> If I have a update statement like
> UPDATE MY_TABLE
> SET FieldName1 = Now(), FieldName2 = :MyVariable
> WHERE FieldName3 = 'Y'
> How can I only update the FieldName2 field if the value of MyVariable is
> NOT NULL ?
This needs to be a decision you make at the application level to not
execute the UPDATE command in the first place. Not every decision needs
to be made by the database. Plus, it will save you the time of a full
network round trip just to get a result from the server that you
affected 0 rows (parsing, optimizing, executing).
Now, if this was just a typo and your :MyVariable was meant to be
@MyVariable (a MySQL user variable) then you can put that test in the
WHERE clause of the command
SET FieldName1 = Now(), FieldName2 = @MyVariable
WHERE FieldName3 = 'Y' AND @MyVariable IS NOT NULL
MySQL Senior Principal Technical Support Engineer
Oracle USA, Inc. - Hardware and Software, Engineered to Work Together.
Office: Blountville, TN