Hi there!
On a stored proc im working on im going to need to update data but the user may only send over 2 out of the 5 possible column changes over, so i was wondering if there was some way to do optional arguments in MySQL Stored Procs and then somehow ignore the columns that are not included...
Here is some psudo code to try and show what i mean:
DoUpdate(Column1 INT DEFAULT NULL, Column2 TEXT DEFAULT NULL, Column3 INT DEFAULT NULL, ID INT)
Begin
UPDATE random_table
IF(Column1 != NULL)
SET column_definition_one = Column1;
END IF
IF(Column2 != NULL)
SET column_definition_two = Column2;
END IF
IF(Column3 != NULL)
SET column_definition_three = Column3;
END IF
WHERE id = ID;
End
As its in a stored proc i dont think there is a way to break apart the SQL like shown, but thats the sort of functionality im going to be after. So depending on the arguments you can constrain the updates that take place?
If anyone has any advice then please shoot it my way 😃