...

View Full Version : MySQL If Statement



ejhern
01-31-2007, 09:38 PM
I am trying to update an existing record or Insert a new line into a MySQL database. I can not seem to get this statement to run. I keep receiving the following message.What am I missing?
'Error in your SQL syntax near 'IF first_name LIKE '.%' AND year_of_grad = '1900' THEN UPDATE Members SET fir' at line 1'
Independently the UPDATE and INSERT statements work just fine.

IF first_name LIKE '.%'AND
year_of_grad='1900'
THEN
UPDATE Members
SET first_name='TOM',
last_name='LastName',
year_of_grad='1900',
date_of_membership=CURDATE()
WHERE
first_name LIKE '.%'AND
year_of_grad='1900'
END
ELSE
INSERT INTO Members SET
first_name='Dick',
last_name='LastName',
year_of_grad='1900',
date_of_membership=CURDATE()
END;

nikkiH
01-31-2007, 11:21 PM
SQL Server needs begin and end. Not sure if MySQL does.



IF yada yada THEN
BEGIN
INSERT ...
END
ELSE
BEGIN
UPDATE ...
END
END


Also assuming this is in a stored procedure, because AFAIK, it won't work as a query.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum