I am following this tutorial http://blogs.msdn.com/b/miah/archive/2008/02/17/sql-if-exists-update-else-insert.aspx I'm on the first more strenuous statement at the moment...
I have produced an error and am not sure what near means:
Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'IF EXISTS (SELECT * FROM radio WHERE em='someone@gmail.com') UPDATE radio ' at line 1
Here is my code:
//var _={'em':'email@address.com','st':'radio_name'};
var mysqlquery=
"IF EXISTS (SELECT * FROM radio WHERE em='"+_.em+"') "+
"UPDATE radio SET ("+
"em='"+_.em+"',"+
"st='"+_.st+"') WHERE em='"+_.em+"' "+
"ELSE "+
"INSERT INTO radio VALUES ("+
"em='"+_.em+"',"+
"st='"+_.st+"')";
I would have thought the error came from me using vars and starting/stopping the string but I don't see an obvious mistake so my question is:
Is this valid syntax for mysql or sql? I'm running a mysql database, I would be interested to know what kind of problem this parse error is producing