MySQL Forums
Forum List  »  Stored Procedures

Re: Dynamic SQL. Is it possible?
Posted by: Roland Bouman
Date: November 04, 2005 08:54AM

Although you can build SQL statements from strings with the prepared statement syntax (see: http://dev.mysql.com/doc/refman/5.0/en/sqlps.html) I advise not to. It's not that this syntax does not work (it works fine, exactly as described in the docs), it just isn't necessary to do it like this. Just do it like this:

UPDATE tablex
SET col1 = COALESCE(par1,col1)
, col2 = COALESCE(par2,col2)
, col3 = COALESCE(par3,col3)

COALESCE will evaluate to the first non-NULL argument value. see: http://dev.mysql.com/doc/refman/5.0/en/comparison-operators.html



Edited 1 time(s). Last edit at 11/04/2005 08:56AM by Roland Bouman.

Options: ReplyQuote


Subject
Views
Written By
Posted
3983
November 04, 2005 01:40AM
2891
November 04, 2005 03:51AM
2937
November 04, 2005 08:51AM
2623
November 23, 2005 10:50AM
2562
November 23, 2005 02:18PM
Re: Dynamic SQL. Is it possible?
2657
November 04, 2005 08:54AM
7205
November 04, 2005 03:40PM
2697
November 04, 2005 05:21PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.